QueryEngine
A query engine wraps a Retriever
and a ResponseSynthesizer
into a pipeline, that will use the query string to fetech nodes and then send them to the LLM to generate a response.
const queryEngine = index.asQueryEngine();
const response = await queryEngine.query({ query: "query string" });
The query
function also supports streaming, just add stream: true
as an option:
const stream = await queryEngine.query({ query: "query string", stream: true });
for await (const chunk of stream) {
process.stdout.write(chunk.response);
}
Sub Question Query Engine
The basic concept of the Sub Question Query Engine is that it splits a single query into multiple queries, gets an answer for each of those queries, and then combines those different answers into a single coherent response for the user. You can think of it as the "think this through step by step" prompt technique but iterating over your data sources!
Getting Started
The easiest way to start trying the Sub Question Query Engine is running the subquestion.ts file in examples.
npx ts-node subquestion.ts