This guide provides comprehensive instructions for integrating Infactory’s APIs into your applications, enabling you to add intelligent data query capabilities with minimal effort.
Before deploying to production, thoroughly test your integration:
1
Test with simple questions
Start with straightforward questions that you know should work.Example: “What is the average sales by region?”
2
Test edge cases
Try questions that might be challenging or at the boundaries of what your queries can handle.Example: “What’s the correlation between customer age and purchase amount in the northeast region for Q2?”
3
Test error scenarios
Deliberately trigger errors to ensure your error handling works properly.Examples:
Use an invalid API key
Ask questions your queries can’t answer
Send malformed requests
4
Performance testing
Test with concurrent users and measure response times.Tools to consider:
Implement caching to improve performance and reduce API calls:
Copy
Ask AI
// Simple in-memory cacheconst cache = new Map();const CACHE_TTL = 1000 * 60 * 5; // 5 minutesasync function queryWithCache(question) { // Generate a cache key from the question const cacheKey = question.trim().toLowerCase(); // Check if we have a fresh cached response const cachedItem = cache.get(cacheKey); if (cachedItem && Date.now() - cachedItem.timestamp < CACHE_TTL) { console.log('Cache hit for:', cacheKey); return cachedItem.data; } // If not in cache or expired, query the API const response = await queryInfactory(question); // Cache the response if successful if (!response.error) { cache.set(cacheKey, { timestamp: Date.now(), data: response }); } return response;}