Find answers from the community

Updated 3 months ago

Hi hi! Two weeks ago I submitted a

Hi hi! Two weeks ago I submitted a question in the issues section (#13102) and I am still stuck with no answer :c does anybody know how to correctly persist/load a MultiModalVectorStoreIndex? I tried various solutions and my code works when I create it from scratch, but when I load it, I always get empty retrieval solution.
L
E
9 comments
This worked for me
Plain Text
from llama_index.core import StorageContext, load_index_from_storage
from llama_index.core.indices import MultiModalVectorStoreIndex
from llama_index.vector_stores.qdrant import QdrantVectorStore
import qdrant_client

client = qdrant_client.QdrantClient(host="localhost", port=6333)

text_store = QdrantVectorStore(
    "text_collection", client=client
)
image_store = QdrantVectorStore(
    "image_collection", client=client
)
storage_context = StorageContext.from_defaults(
    vector_store=text_store, image_store=image_store
)

index = MultiModalVectorStoreIndex.from_documents(
    <documents>, 
    storage_context=storage_context
)

nodes = index.as_retriever().retrieve("test")
print(len(nodes))

index.storage_context.persist(persist_dir="./storage")

text_store = QdrantVectorStore(
    "text_collection", client=client
)
image_store = QdrantVectorStore(
    "image_collection", client=client
)

loaded_storage_context = StorageContext.from_defaults(
    persist_dir="./storage", vector_store=text_store, image_store=image_store
)

index = load_index_from_storage(loaded_storage_context)

nodes = index.as_retriever().retrieve("test")
print(len(nodes))
Your original github issue was using memory mode on qdrant, which does not actually persist anywhere
I think even the persist call is not needed, everything should bein the two vector stores 🤔
I followed some tutorials I found with this qdrant, but my main idea is to store the images anywhere where it would work, use this multi modal index and then load the previously persisted storage context to avoid reparsing all the data. I don't necessarily need qdrant, I am just looking for something to store images and persist them, and nothing works so far 😕
The code I gave above works 😅
You can also ignore qdrant and just do

Plain Text
from llama_index.core import StorageContext, load_index_from_storage
from llama_index.core.indices import MultiModalVectorStoreIndex

index = MultiModalVectorStoreIndex.from_documents(
    <documents>, 
)

nodes = index.as_retriever().retrieve("test")
print(len(nodes))

index.storage_context.persist(persist_dir="./storage")

loaded_storage_context = StorageContext.from_defaults(
    persist_dir="./storage",
)

index = load_index_from_storage(loaded_storage_context)

nodes = index.as_retriever().retrieve("test")
print(len(nodes))
Sorry, I didn't mean it doesn't work, but it requires additional setup with Docker etc., which is what I wanted to avoid
This is exactly what I was looking for! Much simpler than what I tried, I love it, thank you so much!!! I will include it in the issue and close it
Add a reply
Sign up and join the conversation on Discord