Query Transformation
When a user asks a blended or incomplete query, such as:
"How do I deploy it?"
the LLM uses the background context it already has to transform the query into a more meaningful one.
For example:
"How do I deploy a FastAPI application?"
By transforming the query into a more specific one, the system is able to retrieve more relevant documents from the vector database.
For query transformation to work effectively, the LLM should have some background information about the conversation.
Query Expansion
When a user query is converted into an embedding, the point obtained in the vector database may not be close to the most relevant documents.
By expanding the query into different variations, we can retrieve more relevant documents.
Example
Original User Query
"How do I deploy a FastAPI application?"
Expanded Queries
- Deploy FastAPI using Docker
- FastAPI deployment guide
- FastAPI deployment on AWS
- FastAPI with Gunicorn
- FastAPI with Uvicorn
These are different variations of the original user query.
How Does Query Expansion Work?
For each variation of the user query, the system retrieves a set of relevant contexts from the vector database.
During the augmentation phase, the retrieved contexts, along with the original user query, are sent to the LLM so that it can generate more accurate results.
Query Expansion and Query Transformation
Both query expansion and query transformation are performed by the LLM.
- Query Transformation rewrites an incomplete or ambiguous query into a more meaningful query.
- Query Expansion generates multiple variations of the user query to improve document retrieval.
Alternative Approach
Instead of calling the LLM for query expansion, we can use a rule-based approach by storing related queries for a user query as a cluster in the vector database.
When a user submits a query, the system retrieves the related queries from the cluster and uses them to improve document retrieval.
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.