Find answers from the community

Updated 3 months ago

```

Plain Text
base_index = VectorStoreIndex.from_documents(documents, 
                                        storage_context=storage_context,
                                        service_context=service_context,
                                        show_progress=True)


Does this line embed my documents and save them to my custom vector store? If so, can I call it without passing it to a variable, and then simply query the vector store directly, something like

Plain Text
VectorStoreIndex.from_documents(documents, 
                                        storage_context=storage_context,
                                        service_context=service_context,
                                        show_progress=True)
index = VectorStoreIndex.from_vector_store(vector_store=vector_store, 
                                               service_context = service_context)
retriever = index.as_retriever(similarity_top_k = similarity_top_k)


or do I need to pass the from_documents part to a variable even if I don't use it ?
L
b
6 comments
Yea the first line will save things to your vector store

To load the already-created index, you can do just from_vector_store()
one small question related to the above, in the code :

Plain Text
vector_index_chunk = VectorStoreIndex(all_nodes, 
                                      service_context=service_context)
# build retriever
vector_retriever_chunk = vector_index_chunk.as_retriever(similarity_top_k=2)


How can I store my vector_index_chunks to the database ? can I just pass storage_context to the VectorStoreIndex ?
you should be able to yes, assuming your vector_store is setup to store text (most are)
it's pgvector
yea it should πŸ€·β€β™‚οΈ You mentioned a custom vector store before, I'm not sure if that meant you sublcassed your own version or are just using PGVectorStore -- but the base PGVectorStore stores all the nodes in the db
it's PGVectorStore, seems to work perfectly, thanks πŸ™‚
Add a reply
Sign up and join the conversation on Discord