Find answers from the community

s
F
Y
a
P
Updated 2 years ago

Can you explain a few good usecases for Composable Indices within the llama-index library?

@kapa.ai Can you explain a few good usecases for Composable Indices within the llama-index library?
k
3 comments
Please stand by @ryanglambert as I search the knowledge base. We are experiencing especially high traffic right now and might take longer than usual. :wave:
----------------------
Certainly! Composable Indices within the llama-index library allow you to build more complex and powerful index structures by combining multiple indices. Here are a few good use cases:

  1. Synthesis over Heterogeneous Data: LlamaIndex supports synthesizing across heterogeneous data sources by composing a list index over your subindices. This allows you to combine information from different data sources and query them together. Source (https://gpt-index.readthedocs.io/en/latest/use_cases/queries.html)
Plain Text
from llama_index import GPTSimpleVectorIndex, GPTListIndex
from llama_index.indices.composability import ComposableGraph

index1 = GPTSimpleVectorIndex.from_documents(notion_docs)
index2 = GPTSimpleVectorIndex.from_documents(slack_docs)

graph = ComposableGraph.from_indices(GPTListIndex, [index1, index2], index_summaries=["summary1", "summary2"])
response = graph.query("<query_str>", mode="recursive", query_configs=...)


  1. Routing over Heterogeneous Data: LlamaIndex also supports routing over heterogeneous data sources, allowing you to route a query to an underlying Document or a subindex. You can use GPTTreeIndex, GPTKeywordTableIndex, or a GPTVectorStoreIndex for this purpose. Source (https://gpt-index.readthedocs.io/en/latest/use_cases/queries.html)
Plain Text
from llama_index import GPTTreeIndex, GPTSimpleVectorIndex
from llama_index.indices.composability import ComposableGraph

# subindices
index1 = GPTSimpleVectorIndex.from_documents(notion_docs)
index2 = GPTSimpleVectorIndex.from_documents(slack_docs)

# tree index for routing
tree_index = ComposableGraph.from_indices(
    GPTTreeIndex, 
    [index1, index2],
    index_summaries=["summary1", "summary2"]
)

response = tree_index.query(
    "In Notion, give me a summary of the product roadmap.",
    mode="recursive",
    query_configs=...
)
  1. Compare/Contrast Queries: LlamaIndex can support compare/contrast queries by composing a graph over your data. You can also perform compare/contrast queries with a query transformation module, which helps break down a complex query into a simpler one over your existing index structure. Source (https://gpt-index.readthedocs.io/en/latest/use_cases/queries.html)
Plain Text
from gpt_index.indices.query.query_transform.base import DecomposeQueryTransform
decompose_transform = DecomposeQueryTransform(
    llm_predictor_chatgpt, verbose=True
)


These are just a few examples of how Composable Indices can be used within the llama-index library to create more powerful and flexible index structures for various use cases.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord