)
}
```
## Testing Your Q&A System
### Step 4: Test Document Processing
1. **Upload Test Documents**:
- Upload a PDF manual or research paper
- Add a few web articles via URL
- Upload some text files with different topics
2. **Test Question Types**:
```
Factual: "What is the definition of X mentioned in the documents?"
Analytical: "What are the pros and cons of approach Y?"
Comparative: "How does method A compare to method B?"
Summarization: "Summarize the main findings"
```
3. **Verify Citations**:
- Check that citations appear in responses
- Verify citation numbers match source list
- Ensure sources show relevant metadata
## Production Considerations
### Performance Optimization
```typescript
// Implement caching for frequently asked questions
const cacheKey = `qa:${collection}:${hashQuery(question)}`
const cachedResponse = await redis.get(cacheKey)
if (cachedResponse) {
return JSON.parse(cachedResponse)
}
// Cache response for 1 hour
await redis.setex(cacheKey, 3600, JSON.stringify(response))
```
### Advanced Features
1. **Follow-up Questions**:
```typescript
// Track conversation context
const conversationHistory = messages.slice(-6) // Last 3 exchanges
```
2. **Answer Confidence Scoring**:
```typescript
const confidence = calculateConfidence({
searchScore: searchResults.results[0]?.score || 0,
resultCount: searchResults.results.length,
chunkRelevance: avgChunkRelevance
})
```
3. **Multi-language Support**:
```typescript
// Detect document language and adapt search
const detectedLanguage = await detectLanguage(question)
const searchResults = await client.search.documents({
q: question,
filters: {
AND: [{ key: 'language', value: detectedLanguage }]
}
})
```
This recipe provides a complete foundation for building document Q&A systems with accurate citations and source tracking.
---
*Customize this recipe based on your specific document types and use cases.*