VectorStoreIndex.from_documents
, you can simply call the from_documents
method again with the new documents and the same URI. Here's an example:index = VectorStoreIndex.from_documents( [Document(text="The sky is blue")], uri="/tmp/new_dataset" ) # Add more documents index = VectorStoreIndex.from_documents(new_documents, uri="/tmp/new_dataset")
new_documents
is the list of new documents you want to add to the index. The uri
parameter should be the same as the one you used when creating the index initially.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:insert
method of the index to add documents one at a time. Here's an example:from llama_index import VectorStoreIndex index = VectorStoreIndex([]) for doc in documents: index.insert(doc)
documents
is a list of Document
objects that you want to add to the index. This method allows you to add documents to the index one at a time, which can be useful if you are processing documents in a stream or if you want to add documents to the index as they become available.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:from llama_index import VectorStoreIndex, Document # Load the index from storage index = VectorStoreIndex.load_index_from_storage(uri="/path/to/index") # Create a new document doc = Document(text="New document text", id_="new_doc_id") # Insert the new document into the index index.insert(doc)
"/path/to/index"
with the path to your index. The Document
constructor is used to create a new document, and the insert
method is used to add this document to the index.load_index_from_storage
is not mentioned in the provided extracts, so please refer to the LlamaIndex documentation or source code for the correct method.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:service_context
into the insert
method of an index. The insert
method is typically used to add a document to an index, and it's not clear from the provided information whether it accepts a service_context
as an argument.service_context
is used when creating an index or loading an index from storage. For example:from llama_index import StorageContext, load_index_from_storage, ServiceContext # rebuild storage context storage_context = StorageContext.from_defaults(persist_dir="<persist_dir>") # define service context service_context = ServiceContext.from_defaults() # load index index = load_index_from_storage(storage_context, service_context=service_context)
service_context
is passed as an argument to the load_index_from_storage
function. The service_context
contains various settings and helpers that are used by the index.service_context
can be passed to the insert
method, please refer to the LlamaIndex documentation ().Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:VectorStoreIndex
, you can specify the service_context
for each index individually when you create them. Here's an example:from llama_index import VectorStoreIndex, ServiceContext # Define the service context service_context = ServiceContext.from_defaults() # Create a list of indices indices = [] for i in range(5): index = VectorStoreIndex.from_documents(documents, service_context=service_context) indices.append(index)
documents
is a list of documents that you want to add to each index. The service_context
is defined once and then used for each index. This ensures that all indices use the same service context.Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon: