AI Personal Learning
and practical guidance

AI College of Engineering: 2.11 Advanced Query Processing (Query Conversion User Manual)

present (sb for a job etc)

The Query Conversion User's Manual demonstrates the use of the query transformation in the retrieval of the enhanced generation (RAG) Multiple techniques for transformations and decompositions before executing a user query in a query engine, intelligence, or other process. These transformations can improve the quality and relevance of responses in AI applications.

https://github.com/adithya-s-k/AI-Engineering.academy/tree/main/RAG/06_Query_Transformation_RAG


 

Query conversion technology

1. Routing

Routing involves identifying a subset of tools relevant to a given query.

flowchart LR A[User Query] --> B[Selector] B --> C[Tool 1] B --> D[Tool 2] B --> E[Tool N] C & D & E --> F[Selected Tool]

Realization method:

  • utilization LLMSingleSelector maybe LLMMultiSelector Make a selection based on a large language model
  • utilization PydanticSingleSelector maybe PydanticMultiSelector Make function call-based selections
  • utilization ToolMetadata Defining Tool Options

2. Query rewriting

Query rewriting involves generating multiple variants of the original query to improve the retrieval results.

Realization method:

  • utilization PromptTemplate and Large Language Model (LLM) for custom implementations
  • utilization HyDEQueryTransform Perform hypothetical document embedding queries

3. Sub-query generation

This technique decomposes a complex query into multiple subqueries, each oriented to a specific tool.

blank

Realization method:

  • utilization OpenAIQuestionGenerator maybe LLMQuestionGenerator
  • utilization ToolMetadata Defining Tool Options

4. ReAct Intelligent Body Tool Selection

This method uses ReAct The framework determines the tool to be used and the queries to be executed on that tool.

blank

Realization method:

  • utilization ReActChatFormatter Perform input formatting
  • utilization ReActOutputParser Parsing Large Language Model Output
  • utilization FunctionTool Definition tools

 

utilization

Each of the query transformation techniques can be used as modular components in a larger system. The following are examples of basic usage of query rewriting:

from llama_index.core import PromptTemplate
from llama_index.llms.openai import OpenAI
query_gen_prompt = PromptTemplate("Your prompt template is here")
llm = OpenAI(model="gpt-3.5-turbo")
def generate_queries(query: str, llm, num_queries: int = 4):
response = llm.predict(query_gen_prompt, num_queries=num_queries, query=query)
queries = response.split("\n")
return queries
queries = generate_queries("Your queries are here", llm)

 

summarize

The Query Transformation User Manual provides a complete set of techniques to help developers enhance query processing in AI applications. By utilizing these transformation techniques, developers can create more powerful and accurate information retrieval and Q&A systems.

For more on detailed implementation and integration with a specific query engine or retriever, please refer to the LlamaIndex documentation.

This README provides an overview of the Query Transformation User's Manual, including brief descriptions and Mermaid charts for each query transformation technique, covering the four main query transformation techniques: Routing, Query Rewriting, SubQuery Generation, and ReAct Intelligent Body Tool Selection.

Each section includes a flowchart visualization, a brief description of the technology, and basic implementation details. In addition, this README includes a simple usage example of query rewriting to provide users with a starting point.

What part of this README would you like me to expand or modify in detail?

AI Easy Learning

The layman's guide to getting started with AI

Help you learn how to utilize AI tools at a low cost and from a zero base.AI, like office software, is an essential skill for everyone. Mastering AI will give you an edge in your job search and half the effort in your future work and studies.

View Details>
May not be reproduced without permission:Chief AI Sharing Circle " AI College of Engineering: 2.11 Advanced Query Processing (Query Conversion User Manual)

Chief AI Sharing Circle

Chief AI Sharing Circle specializes in AI learning, providing comprehensive AI learning content, AI tools and hands-on guidance. Our goal is to help users master AI technology and explore the unlimited potential of AI together through high-quality content and practical experience sharing. Whether you are an AI beginner or a senior expert, this is the ideal place for you to gain knowledge, improve your skills and realize innovation.

Contact Us
en_USEnglish