Closed harshachopra507 closed 2 weeks ago
To add new documents to an existing collection in Qdrant Vector Store, you can use the add
method of the QdrantVectorStore
class. Here’s a step-by-step guide:
QdrantVectorStore
with the existing collection name.TextNode
objects: Each TextNode
should contain the text, unique ID, relationships, metadata, and embeddings.add
method of the QdrantVectorStore
instance to add the new nodes.Here is an example code snippet:
from llama_index.legacy.schema import TextNode, NodeRelationship, RelatedNodeInfo
from llama_index.legacy.vector_stores import QdrantVectorStore
import qdrant_client
# Step 1: Create a Qdrant client
client = qdrant_client.QdrantClient(":memory:")
# Step 2: Initialize the QdrantVectorStore with the existing collection name
qdrant_vector_store = QdrantVectorStore(collection_name="existing_collection", client=client)
# Step 3: Create a list of TextNode objects with embeddings
new_node_embeddings = [
TextNode(
text="new document text 1",
id_="new-doc-id-1",
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="source-id-1")},
metadata={
"author": "Author Name",
"theme": "Theme",
},
embedding=[0.5, 0.5], # Example embedding
),
TextNode(
text="new document text 2",
id_="new-doc-id-2",
relationships={NodeRelationship.SOURCE: RelatedNodeInfo(node_id="source-id-2")},
metadata={
"author": "Another Author",
"theme": "Another Theme",
},
embedding=[0.2, 0.8], # Example embedding
),
]
# Step 4: Add the new nodes to the Qdrant collection
qdrant_vector_store.add(new_node_embeddings)
This will add the new documents to the existing collection, and if the collection is not already initialized, it will be created with the appropriate vector size.
To continue the conversation, mention @dosu.
Question Validation
Question
How can I add new documents in an existing collection in Qdrant Vector Store? The existing collection already contains chunk embedding for few documents.