Overview
Query engines provide interfaces for querying indexed data and generating responses. They combine retrieval with response synthesis to answer questions over your data.BaseQueryEngine
Abstract base class for all query engines.Methods
Query the engine with streaming or non-streaming responseNon-streaming:Streaming:
Retrieve relevant nodes without generating a response
QueryBundle
Enhanced query object with optional embeddings.Usage Examples
Basic Query
Streaming Query
Retrieve Only
QueryBundle with Custom Embeddings
Advanced Query Engines
RetrieverQueryEngine
Query engine that uses a retriever and response synthesizer.SubQuestionQueryEngine
Breaks down complex queries into sub-questions.RouterQueryEngine
Routes queries to appropriate query engines based on content.Response Synthesis
Query engines use response synthesizers to generate answers:Query Events
Query engines emit events during execution:Customization
Custom Query Engine
Best Practices
- Use streaming for long responses: Improves perceived latency
- Inspect source nodes: Verify response quality by checking retrieved sources
- Configure retrieval parameters: Adjust top_k and similarity threshold for better results
- Handle errors gracefully: Implement error handling for failed queries
- Cache embeddings: Reuse QueryBundle with embeddings for repeated queries