mirror of
https://github.com/qdrant/fastembed.git
synced 2026-10-03 19:37:46 -05:00
7.7 KiB
7.7 KiB
In [1]:
!pip install 'qdrant-client[fastembed]' --quiet --upgradeIn [2]:
from qdrant_client import QdrantClientIn [3]:
# Example list of documents
documents: list[str] = [
"Maharana Pratap was a Rajput warrior king from Mewar",
"He fought against the Mughal Empire led by Akbar",
"The Battle of Haldighati in 1576 was his most famous battle",
"He refused to submit to Akbar and continued guerrilla warfare",
"His capital was Chittorgarh, which he lost to the Mughals",
"He died in 1597 at the age of 57",
"Maharana Pratap is considered a symbol of Rajput resistance against foreign rule",
"His legacy is celebrated in Rajasthan through festivals and monuments",
"He had 11 wives and 17 sons, including Amar Singh I who succeeded him as ruler of Mewar",
"His life has been depicted in various films, TV shows, and books",
]In [4]:
client = QdrantClient(":memory:")
client.add(collection_name="test_collection", documents=documents)Out [4]:
100%|██████████| 77.7M/77.7M [00:05<00:00, 14.6MiB/s]
['4fa8b10c78da4b18ba0830ba8a57367a', '2eae04b515ee4e9185a9a0e6be812bba', 'c6039f88486f47f1835ae3b069c5823c', 'c2c8c51e305144d1917b373125fb4d95', '79fd23b9ec0648cdab38d1947c6b933e', '036aa200d8c3492b8a438e4f825f5e7f', 'c35c77f3ea37460a9a13723fb77b7367', '6ebccbca571b40d0ab6e83e5e0f2f562', '38048c2ccc1d4962a4f8f1bd89c8357a', 'c6b09308360140c7b4f106af3658a31e']
In [5]:
# Prepare your documents, metadata, and IDs
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
metadata = [
{"source": "Langchain-docs"},
{"source": "Linkedin-docs"},
]
ids = [42, 2]
# Use the new add method
client.add(collection_name="demo_collection", documents=docs, metadata=metadata, ids=ids)Out [5]:
[42, 2]
In [6]:
search_result = client.query(
collection_name="demo_collection", query_text="This is a query document"
)
print(search_result)[QueryResponse(id=42, embedding=None, metadata={'document': 'Qdrant has Langchain integrations', 'source': 'Langchain-docs'}, document='Qdrant has Langchain integrations', score=0.8276550115796268), QueryResponse(id=2, embedding=None, metadata={'document': 'Qdrant also has Llama Index integrations', 'source': 'Linkedin-docs'}, document='Qdrant also has Llama Index integrations', score=0.8265536935180283)]