Find answers from the community

Updated 8 months ago

query single or multiple indexes base on user question

Hi everyone,

I'm working to extract information from books from different categories. My objective is to ensure queries about a specific question only fetch books from a specific category, using a setup where each book has its own index. I'm considering the Recursive Retriever and Document Agents for this task but am uncertain about the optimal setup, particularly for categorization.
What's the best approach to ensure queries are category-specific and can have one or multiple index selected for response ?

Appreciate any insights!
x
L
7 comments
Hi @WhiteFang_Jr @Logan M any recommendation for this? Thanks
Yea having an index per category and having good descriptions for each index, an agent or router would work fine
If I understand correclty, I need to classify books into categories, where each category will have its own index. For example, categories like "Fiction", "Non-Fiction", "Science", "History", etc.

For each category, you'll create a separate index and populate them with each books' description

Example Index Structure:

Index Name: Fiction
Description: Title 1, Author, Summary, Genre, Year, etc.
Description: Title 2, Author, Summary, Genre, Year, etc.
Description: Title 3, Author, Summary, Genre, Year, etc.
...

Index Name: Science
Description: Title 1, Author, Summary, Genre, Year, etc.
Description: Title 2, Author, Summary, Genre, Year, etc.
Description: Title 3, Author, Summary, Genre, Year, etc.
...


When performing a search query, route to category (index) to query against based on the user's input.

If a user is interested in "Science" books about "Quantum Mechanics", would direct the query specifically to the "Science" index.

Query Example:
User Query: "Quantum Mechanics"
Targeted Index(es): Science
Result: Books related to Quantum Mechanics from the Science category.

What is not clear for me how to create this category index, can you give me some example ? Then how to map to this category index what indexes to query for each book ?
Thanks
Once you have a category for a document, you can add it to the index for that category

Then you can use something like an agent or router to help use the correct index for the user query. Here's an example with an agent
https://docs.llamaindex.ai/en/stable/examples/agent/openai_agent_with_query_engine/?h=query+engine+tools
I'm not using OpenAI, will this agent work with Claude or other LLM ?
yea, you can do the same with a react agent (this works with any LLM)
https://docs.llamaindex.ai/en/stable/examples/agent/react_agent_with_query_engine/?h=query+engine+tools

And actually, if you are using claude, you can use their function calling
https://docs.llamaindex.ai/en/latest/examples/agent/anthropic_agent/?h=anthropic
Many thanks, I will try
Add a reply
Sign up and join the conversation on Discord