Find answers from the community

Updated 2 years ago

I created an index for each file that is

I created an index for each file that is uploaded to my server. Now, I'd like users to be able to select multiple files and query them as 1 unified index. I did, this:
Plain Text
# Create index from requested docs
    indices = []
    summaries = []
    service_context = _create_service_context()
    for index_id in data["indexes"]:
        persist_dir = f"/az/indexes/{index_id}" # test index
        storage_context = StorageContext.from_defaults(persist_dir=persist_dir)
        index = load_index_from_storage(
            storage_context=storage_context,
            service_context=service_context,
        )
        summaries.append("")
        indices.append(index)
    graph = ComposableGraph.from_indices(GPTListIndex, indices, summaries, service_context=service_context)
    query_engine = graph.as_query_engine()

    response = str(query_engine.query(data['query'])).replace("\n", " ")

It appears to call open ai multiple times when I expect it to call once on the merged index. Am I combining the indexes incorrectly to create a merged index?
O
L
4 comments
@Logan M , do you have any resources/thoughts on this?
@Orion Pax right thanks for the ping, forgot to get to this lol

Since you've combined all sub-indexes with a top level index, for each query the LLM will be called to generate an answer for each sub index, and then a final LLM call for the top level index

So, combing them this way isn't quite "merging" them

Currently there isn't quite a way to merge indexes the way you are intending. Really needs a PR to add that functionality πŸ˜…
I see. That's what I suspected was happening
You can try an change the top level index to another vector index to make it a bit more similar to merging. Or even trying the new router query engine might be a good experience as well
Add a reply
Sign up and join the conversation on Discord