vector index store initialization issue #10954
Replies: 3 comments
-
🤖 Hey @rahulkrprajapati, great to see you back! Hope you're doing well. To initialize an empty Here is an example of how you can do this: vector_store = ... # Your VectorStore object
service_context = ... # Your ServiceContext object (optional)
index = VectorStoreIndex.from_vector_store(vector_store, service_context) Please note that the After initializing the Here is an example of how you can insert nodes: nodes = [...] # Your list of BaseNode objects
index.insert_nodes(nodes) This is supported by the following code in the provided context: @classmethod
def from_vector_store(
cls,
vector_store: VectorStore,
service_context: Optional[ServiceContext] = None,
**kwargs: Any,
) -> "VectorStoreIndex":
if not vector_store.stores_text:
raise ValueError(
"Cannot initialize from a vector store that does not store text."
)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
return cls(
nodes=[], service_context=service_context, storage_context=storage_context
)
def insert_nodes(self, nodes: Sequence[BaseNode], **insert_kwargs: Any) -> None:
"""Insert nodes.
NOTE: overrides BaseIndex.insert_nodes.
VectorStoreIndex only stores nodes in document store
if vector store does not store text
"""
self._insert(nodes, **insert_kwargs)
self._storage_context.index_store.add_index_struct(self._index_struct) You can find more details in the source code. Sources
|
Beta Was this translation helpful? Give feedback.
-
@dosu-bot I don't have a vector store defined yet. But I want the load the doc store and index store as below
and later on I also want to add new documents to the index store as: base_index.insert_nodes(leaf_nodes) |
Beta Was this translation helpful? Give feedback.
-
🤖 Based on the error message you're encountering, it seems like you're trying to initialize a Here's how you can do it: from llama_index.core import VectorStoreIndex, StorageContext
from llama_index.vector_stores.pinecone import PineconeVectorStore
import pinecone
# init pinecone
pinecone.init(api_key="<api_key>", environment="<environment>")
pinecone.create_index(
"quickstart", dimension=1536, metric="euclidean", pod_type="p1"
)
# construct vector store and customize storage context
storage_context = StorageContext.from_defaults(
vector_store=PineconeVectorStore(pinecone.Index("quickstart"))
)
# Initialize an empty VectorStoreIndex
index = VectorStoreIndex(storage_context=storage_context) In the above code, we're initializing Pinecone, which is a vector database, and using it as the vector store for our To add new documents to the index store, you can use the from llama_index.core import SimpleDirectoryReader
# Load documents
documents = SimpleDirectoryReader(
"../../examples/data/paul_graham"
).load_data()
# Add documents to the index
index.from_documents(documents) In this code, we're loading documents from a directory and adding them to the index using the Please replace You can find more details about initializing a I hope this helps! If you have any other questions or run into any issues, feel free to ask. Sources
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I wanted to initialzie an empty VectorStoreIndex by providing just a storage_context.
But I'm getting an error:
Considering I would be inserting the nodes later on what would be the correct way of initialisation and reloading of indices?
Beta Was this translation helpful? Give feedback.
All reactions