mirror of
https://github.com/qdrant/qdrant-client.git
synced 2026-10-03 19:37:43 -05:00
* deprecated recreate_collection from tests * checked if collection exists before deletion * reverted deletion of recreate_collection * added missing collection_exsits before deletion * nit if condition * fix type hint in local_collection * removed run mypy on async client generator * added checks for create_collection if exists * nit change collection name * add else to create_collection * nit * nit * refactoring: remove redundant checks * fix: do not test collection_exists through itself * refactoring: remove redundant collection exists checks * fix: remove redundant collection exists checks * refactoring: remove redundant collection checks * refactoring: remove redundant collection existence check in test sparse search * refactoring: remove redundant checks in test_updates * refactoring: remove redundant checks * fix: remove redundant checks * refactoring: remove redundant checks * refactoring: remove redundant imports * new: add recreate collection test --------- Co-authored-by: George Panchuk <george.panchuk@qdrant.tech>
9.3 KiB
9.3 KiB
In [1]:
!pip install 'qdrant-client[fastembed]' --quietIn [2]:
from qdrant_client import QdrantClient
# client = QdrantClient(path="path/to/db") # Persists changes to disk
# or
client = QdrantClient(":memory:")In [3]:
# Prepare your documents, metadata, and IDs
docs = ["Qdrant has Langchain integrations", "Qdrant also has Llama Index integrations"]
client.add(
collection_name="demo_collection",
documents=docs,
)Out [3]:
['a3e23385a815464385a7589443f850db', 'd5bef7146f1541518cd767313f6569d5']
In [4]:
# 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 [4]:
[42, 2]
In [5]:
search_result = client.query(
collection_name="demo_collection",
query_text="This is a query document",
limit=1
)
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)]
In [6]:
from qdrant_client.http.models import Distance, VectorParams
if not client.collection_exists("test_collection"):
client.create_collection(
collection_name="test_collection",
vectors_config=VectorParams(size=4, distance=Distance.DOT),
)Out [6]:
True
In [7]:
from qdrant_client.http.models import PointStruct
operation_info = client.upsert(
collection_name="test_collection",
wait=True,
points=[
PointStruct(id=1, vector=[0.05, 0.61, 0.76, 0.74], payload={"city": "Berlin"}),
PointStruct(id=2, vector=[0.19, 0.81, 0.75, 0.11], payload={"city": "London"}),
PointStruct(id=3, vector=[0.36, 0.55, 0.47, 0.94], payload={"city": "Moscow"}),
PointStruct(id=4, vector=[0.18, 0.01, 0.85, 0.80], payload={"city": "New York"}),
PointStruct(id=5, vector=[0.24, 0.18, 0.22, 0.44], payload={"city": "Beijing"}),
PointStruct(id=6, vector=[0.35, 0.08, 0.11, 0.44], payload={"city": "Mumbai"}),
]
)
print(operation_info)operation_id=0 status=<UpdateStatus.COMPLETED: 'completed'>
In [8]:
search_result = client.search(
collection_name="test_collection",
query_vector=[0.18, 0.81, 0.75, 0.12],
limit=1
)
print(search_result)[ScoredPoint(id=2, version=0, score=1.2660000014305115, payload={'city': 'London'}, vector=None)]
In [9]:
from qdrant_client.http.models import Filter, FieldCondition, MatchValue
search_result = client.search(
collection_name="test_collection",
query_vector=[0.2, 0.1, 0.9, 0.7],
query_filter=Filter(
must=[
FieldCondition(
key="city",
match=MatchValue(value="London")
)
]
),
limit=1
)
print(search_result)[ScoredPoint(id=2, version=0, score=0.8709999993443489, payload={'city': 'London'}, vector=None)]