nasirus / llama_index

MIT License
1 stars 0 forks source link

How can merge multi index file #7

Closed nasirus closed 1 year ago

nasirus commented 1 year ago

Hi,

For example I have 2 folder, folder 1 I use GPTTreeIndex and save to index1.json. And folder 2 I save to index2.json. So, now I want to load 2 index files. Ho can I do it?

nasirus commented 1 year ago

Response: Hi there,

You can use the GPTListIndex to merge multiple indices. The GPTListIndex allows you to combine multiple GPTSimpleVectorIndex objects into a single index.

Here is an example of how to do this:

from llama_index import GPTSimpleVectorIndex, GPTListIndex

# Load the indices
index1 = GPTSimpleVectorIndex.load_from_disk('index1.json')
index2 = GPTSimpleVectorIndex.load_from_disk('index2.json')

# Create a list of indices
indices = [index1, index2]

# Create a GPTListIndex from the list of indices
list_index = GPTListIndex(indices)

# Save the GPTListIndex to disk
list_index.save_to_disk('list_index.json')

You can then load the GPTListIndex from disk and use it as you would any other index.

I hope this helps!

Best, The Llama Index Team