VectorStoreIndex
, you can use the insert
method. However, the insert
method does not automatically handle the assignment of sequential identifiers. You would need to manage the identifiers yourself before adding the nodes to the index.from llama_index.core import VectorStoreIndex index = VectorStoreIndex([]) for doc in documents: index.insert(doc)
from llama_index.core.schema import TextNode # Assume last_id is the identifier of the last node in your index last_id = get_last_id_from_your_index() nodes = [] for i, text_chunk in enumerate(new_text_chunks): node_id = last_id + i + 1 node = TextNode(text=text_chunk, id_=str(node_id)) nodes.append(node) index = VectorStoreIndex(nodes)
get_last_id_from_your_index()
function is a placeholder for the function or method you would use to retrieve the last identifier from your index.get_last_id_from_your_index()
function. This function's implementation would depend on the specifics of your VectorStoreIndex
instance and how you're storing and managing your nodes. VectorStoreIndex
class for more information on how you might implement this function.VectorStoreIndex
, you can use the as_retriever
method to create a retriever and then use the retrieve
method of the retriever to retrieve nodes based on a query. The as_retriever
method can take a vector_store_query_mode
parameter to specify the query mode. retriever = index.as_retriever(vector_store_query_mode="default") results = retriever.retrieve("Who directed inception?")
retriever = index.as_retriever(vector_store_query_mode="semantic_hybrid") results = retriever.retrieve("Who wrote Harry Potter?")
retriever = index.as_retriever( vector_store_query_mode="mmr", similarity_top_k=3, vector_store_kwargs={"mmr_threshold": 1.0}, ) nodes = retriever.retrieve("What did the author do during his time in Y Combinator?")
results
or nodes
will contain the retrieved nodes.VectorStoreIndex
, you first need to retrieve the nodes themselves. Once you have the nodes, you can access their metadata through the metadata
attribute. Here's an example:from llama_index.core import VectorStoreIndex # Assume you have an index and a query index = VectorStoreIndex(nodes) query = "Your query here" # Create a retriever and retrieve nodes retriever = index.as_retriever() nodes = retriever.retrieve(query) # Access metadata of each node for node in nodes: print(node.metadata)
nodes
is a list of nodes retrieved based on the query. Each node is an instance of a class (like TextNode
or EntityNode
) that has a metadata
attribute. This attribute is a dictionary that contains the metadata of the node.VectorStoreIndex
in LlamaIndex is designed to retrieve nodes based on a query. The main purpose of this index is to enable efficient retrieval of relevant nodes for a given query. VectorStoreIndex
without a query. VectorStoreIndex
class.