Find answers from the community

Updated 2 months ago

Hi!

Hi!
I get an error when loading vectors from chromadb on disk:

Plain Text
Traceback (most recent call last):
  File "/home/shawn/llamaindex/2_read_documents_from_db.py", line 21, in <module>
    index = VectorStoreIndex.from_documents(
  File "/home/shawn/llamaindex/venv/lib/python3.10/site-packages/llama_index/core/indices/base.py", line 136, in from_documents
    docstore.set_document_hash(doc.get_doc_id(), doc.hash)
AttributeError: 'tuple' object has no attribute 'get_doc_id'


I followed the examples from this doc: https://docs.llamaindex.ai/en/stable/understanding/storing/storing.html
Code and versions in thread 🧵
s
L
5 comments
Plain Text
import chromadb
from llama_index.core import VectorStoreIndex
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.core import StorageContext


# initialize client, setting path to save data
db = chromadb.PersistentClient(path="./talents_db")

# create collection
chroma_collection = db.get_or_create_collection("business_analyst")

# assign chroma as the vector_store to the context
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)

# create your index
index = VectorStoreIndex.from_documents(
    vector_store, storage_context=storage_context
)

# create a query engine and query
query_engine = index.as_query_engine()
response = query_engine.query("What are the main steps for requirements engineering?")
print(response)
you are using from_documents
Should be from_vector_store()
oops! yup that works hehe, thank you!!
Add a reply
Sign up and join the conversation on Discord