Skip to main content

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

method
Query the engine with streaming or non-streaming responseNon-streaming:
Streaming:
method
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

  1. Use streaming for long responses: Improves perceived latency
  2. Inspect source nodes: Verify response quality by checking retrieved sources
  3. Configure retrieval parameters: Adjust top_k and similarity threshold for better results
  4. Handle errors gracefully: Implement error handling for failed queries
  5. Cache embeddings: Reuse QueryBundle with embeddings for repeated queries