fix and refactor python examples (#770)

* fix: fix points selector bugs, refactor code

* fix: fix and refactor embeddings

* fix: fix and refactor frameworks

* refactor: refactor guides

* fix: fix and refactor aleph-alpha tutorial

* fix: fix and refactor tutorials

* refactoring: refactor quick-start

* fix: address review comments

* fix: replace remaining host
This commit is contained in:
George
2024-04-03 13:17:45 +02:00
committed by GitHub
parent 5441805449
commit 92f8196651
38 changed files with 202 additions and 233 deletions
@@ -63,10 +63,9 @@ curl -X PUT http://localhost:6333/collections/test_collection1 \
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -195,9 +194,8 @@ curl -X PUT http://localhost:6333/collections/test_collection2 \
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -325,10 +323,10 @@ curl -X PUT http://localhost:6333/collections/test_collection3 \
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -487,10 +485,9 @@ curl -X PUT http://localhost:6333/collections/test_collection4 \
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -1419,7 +1416,7 @@ curl -X GET http://localhost:6333/collections/test_collection2/aliases
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.get_collection_aliases(collection_name="{collection_name}")
```
@@ -1472,7 +1469,7 @@ curl -X GET http://localhost:6333/aliases
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.get_aliases()
```
@@ -1525,7 +1522,7 @@ curl -X GET http://localhost:6333/collections
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.get_collections()
```
@@ -36,10 +36,9 @@ POST /collections/{collection_name}/points/recommend
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.recommend(
collection_name="{collection_name}",
@@ -455,12 +454,11 @@ POST /collections/{collection_name}/points/recommend/batch
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
filter = models.Filter(
filter_ = models.Filter(
must=[
models.FieldCondition(
key="city",
@@ -473,9 +471,9 @@ filter = models.Filter(
recommend_queries = [
models.RecommendRequest(
positive=[100, 231], negative=[718], filter=filter, limit=3
positive=[100, 231], negative=[718], filter=filter_, limit=3
),
models.RecommendRequest(positive=[200, 67], negative=[300], filter=filter, limit=3),
models.RecommendRequest(positive=[200, 67], negative=[300], filter=filter_, limit=3),
]
client.recommend_batch(collection_name="{collection_name}", requests=recommend_queries)
@@ -703,10 +701,9 @@ POST /collections/{collection_name}/points/discover
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
discover_queries = [
models.DiscoverRequest(
@@ -906,10 +903,9 @@ POST /collections/{collection_name}/points/discover
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
discover_queries = [
models.DiscoverRequest(
@@ -52,10 +52,9 @@ POST /collections/{collection_name}/points/scroll
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.scroll(
collection_name="{collection_name}",
@@ -729,7 +728,7 @@ Example:
```
```python
FieldCondition(
models.FieldCondition(
key="color",
match=models.MatchAny(any=["black", "yellow"]),
)
@@ -785,7 +784,7 @@ Example:
```
```python
FieldCondition(
models.FieldCondition(
key="color",
match=models.MatchExcept(**{"except": ["black", "yellow"]}),
)
@@ -36,7 +36,7 @@ PUT /collections/{collection_name}/index
```python
from qdrant_client import QdrantClient
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_payload_index(
collection_name="{collection_name}",
@@ -141,10 +141,9 @@ PUT /collections/{collection_name}/index
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_payload_index(
collection_name="{collection_name}",
@@ -316,16 +315,15 @@ PUT /collections/{collection_name}/index
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_payload_index(
collection_name="{collection_name}",
field_name="name_of_the_field_to_index",
field_schema=models.IntegerIndexParams(
type="integer",
type=models.IntegerIndexType.INTEGER,
lookup=False,
range=True,
),
@@ -200,10 +200,9 @@ PUT /collections/{collection_name}/points
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient(host="localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.upsert(
collection_name="{collection_name}",
@@ -768,9 +767,7 @@ POST /collections/{collection_name}/points/payload/clear
```python
client.clear_payload(
collection_name="{collection_name}",
points_selector=models.PointIdsList(
points=[0, 3, 100],
),
points_selector=[0, 3, 100],
)
```
@@ -82,10 +82,9 @@ PUT /collections/{collection_name}/points
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.upsert(
collection_name="{collection_name}",
@@ -1212,9 +1211,7 @@ POST /collections/{collection_name}/points/vectors/delete
```python
client.delete_vectors(
collection_name="{collection_name}",
points_selector=models.PointIdsList(
points=[0, 3, 100],
),
points=[0, 3, 100],
vectors=["text", "image"],
)
```
@@ -1955,7 +1952,7 @@ POST /collections/{collection_name}/points/batch
```python
client.batch_update_points(
collection_name=collection_name,
collection_name="{collection_name}",
update_operations=[
models.UpsertOperation(
upsert=models.PointsList(
@@ -83,10 +83,9 @@ POST /collections/{collection_name}/points/search
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -250,9 +249,8 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -358,10 +356,9 @@ POST /collections/{collection_name}/points/search
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -562,9 +559,8 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -656,10 +652,9 @@ POST /collections/{collection_name}/points/search
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -808,12 +803,11 @@ POST /collections/{collection_name}/points/search/batch
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
filter = models.Filter(
filter_ = models.Filter(
must=[
models.FieldCondition(
key="city",
@@ -825,8 +819,8 @@ filter = models.Filter(
)
search_queries = [
models.SearchRequest(vector=[0.2, 0.1, 0.9, 0.7], filter=filter, limit=3),
models.SearchRequest(vector=[0.5, 0.3, 0.2, 0.3], filter=filter, limit=3),
models.SearchRequest(vector=[0.2, 0.1, 0.9, 0.7], filter=filter_, limit=3),
models.SearchRequest(vector=[0.5, 0.3, 0.2, 0.3], filter=filter_, limit=3),
]
client.search_batch(collection_name="{collection_name}", requests=search_queries)
@@ -1003,7 +997,7 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -1185,7 +1179,7 @@ POST /collections/{collection_name}/points/search/groups
client.search_groups(
collection_name="{collection_name}",
# Same as in the regular search() API
query_vector=g,
query_vector=[1.1],
# Grouping parameters
group_by="document_id", # Path of the field to group by
limit=4, # Max amount of groups
@@ -51,7 +51,7 @@ POST /collections/{collection_name}/snapshots
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_snapshot(collection_name="{collection_name}")
```
@@ -103,7 +103,7 @@ DELETE /collections/{collection_name}/snapshots/{snapshot_name}
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.delete_snapshot(
collection_name="{collection_name}", snapshot_name="{snapshot_name}"
@@ -155,7 +155,7 @@ GET /collections/{collection_name}/snapshots
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.list_snapshots(collection_name="{collection_name}")
```
@@ -241,7 +241,7 @@ PUT /collections/{collection_name}/snapshots/recover
```python
from qdrant_client import QdrantClient
client = QdrantClient("qdrant-node-2", port=6333)
client = QdrantClient(url="http://qdrant-node-2:6333")
client.recover_snapshot(
"{collection_name}",
@@ -326,7 +326,7 @@ PUT /collections/{collection_name}/snapshots/recover
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("qdrant-node-2", port=6333)
client = QdrantClient(url="http://qdrant-node-2:6333")
client.recover_snapshot(
"{collection_name}",
@@ -371,7 +371,7 @@ POST /snapshots
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_full_snapshot()
```
@@ -421,7 +421,7 @@ DELETE /snapshots/{snapshot_name}
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.delete_full_snapshot(snapshot_name="{snapshot_name}")
```
@@ -56,7 +56,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -168,7 +168,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -293,7 +293,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -17,6 +17,7 @@ be done in the following way:
```python
import qdrant_client
from qdrant_client.models import Batch
from aleph_alpha_client import (
Prompt,
@@ -25,7 +26,6 @@ from aleph_alpha_client import (
SemanticRepresentation,
ImagePrompt
)
from qdrant_client.http.models import Batch
aa_token = "<< your_token >>"
model = "luminous-base"
@@ -35,7 +35,7 @@ bedrock_client = session.client(
aws_secret_access_key="<YOUR_AWS_SECRET_KEY>",
)
qdrant_client = QdrantClient(location="http://localhost:6333")
qdrant_client = QdrantClient(url="http://localhost:6333")
qdrant_client.create_collection(
"{collection_name}",
@@ -18,8 +18,7 @@ The embeddings returned by co.embed API might be used directly in the Qdrant cli
```python
import cohere
import qdrant_client
from qdrant_client.http.models import Batch
from qdrant_client.models import Batch
cohere_client = cohere.Client("<< your_api_key >>")
qdrant_client = qdrant_client.QdrantClient()
@@ -55,12 +54,11 @@ documents with the Embed v3 model:
```python
import cohere
import qdrant_client
from qdrant_client.http.models import Batch
from qdrant_client.models import Batch
cohere_client = cohere.Client("<< your_api_key >>")
qdrant_client = qdrant_client.QdrantClient()
qdrant_client.upsert(
client = qdrant_client.QdrantClient()
client.upsert(
collection_name="MyCollection",
points=Batch(
ids=[1],
@@ -76,9 +74,9 @@ qdrant_client.upsert(
Once the documents are indexed, you can search for the most relevant documents using the Embed v3 model:
```python
qdrant_client.search(
client.search(
collection_name="MyCollection",
query=cohere_client.embed(
query_vector=cohere_client.embed(
model="embed-english-v3.0", # New Embed v3 model
input_type="search_query", # Input type for search queries
texts=["The best vector database"],
@@ -43,11 +43,13 @@ The following example shows how to embed a document with the `models/embedding-0
```python
import google.generativeai as gemini_client
from qdrant_client import QdrantClient
from qdrant_client.http.models import Distance, PointStruct, VectorParams
from qdrant_client.models import Distance, PointStruct, VectorParams
collection_name = "example_collection"
GEMINI_API_KEY = "YOUR GEMINI API KEY" # add your key here
client = QdrantClient(url="http://localhost:6333")
gemini_client.configure(api_key=GEMINI_API_KEY)
texts = [
"Qdrant is a vector database that is compatible with Gemini.",
@@ -83,7 +85,7 @@ points = [
### Create Collection
```python
search_client.create_collection(collection_name, vectors_config=
client.create_collection(collection_name, vectors_config=
VectorParams(
size=768,
distance=Distance.COSINE,
@@ -94,7 +96,7 @@ search_client.create_collection(collection_name, vectors_config=
### Add these into the collection
```python
search_client.upsert(collection_name, points)
client.upsert(collection_name, points)
```
## Searching for documents with Qdrant
@@ -102,7 +104,7 @@ search_client.upsert(collection_name, points)
Once the documents are indexed, you can search for the most relevant documents using the same model with the `retrieval_query` task type:
```python
search_client.search(
client.search(
collection_name=collection_name,
query_vector=gemini_client.embed_content(
model="models/embedding-001",
@@ -16,8 +16,7 @@ To call their endpoint, all you need is an API key obtainable [here](https://jin
import qdrant_client
import requests
from qdrant_client.http.models import Distance, VectorParams
from qdrant_client.http.models import Batch
from qdrant_client.models import Distance, VectorParams, Batch
# Provide Jina API key and choose one of the available models.
# You can get a free trial key here: https://jina.ai/embeddings/
@@ -43,8 +42,8 @@ embeddings = [d["embedding"] for d in response.json()["data"]]
# Index the embeddings into Qdrant
qdrant_client = qdrant_client.QdrantClient(":memory:")
qdrant_client.create_collection(
client = qdrant_client.QdrantClient(":memory:")
client.create_collection(
collection_name="MyCollection",
vectors_config=VectorParams(size=EMBEDDING_SIZE, distance=Distance.DOT),
)
@@ -22,11 +22,12 @@ And then we set this up:
```python
from mistralai.client import MistralClient
from qdrant_client import QdrantClient
from qdrant_client.http.models import PointStruct, VectorParams, Distance
from qdrant_client.models import PointStruct, VectorParams, Distance
collection_name = "example_collection"
MISTRAL_API_KEY = "your_mistral_api_key"
search_client = QdrantClient(":memory:")
client = QdrantClient(":memory:")
mistral_client = MistralClient(api_key=MISTRAL_API_KEY)
texts = [
"Qdrant is the best vector search engine!",
@@ -65,13 +66,12 @@ points = [
## Create a collection and Insert the documents
```python
search_client.create_collection(collection_name, vectors_config=
VectorParams(
client.create_collection(collection_name, vectors_config=VectorParams(
size=1024,
distance=Distance.COSINE,
)
)
search_client.upsert(collection_name, points)
client.upsert(collection_name, points)
```
## Searching for documents with Qdrant
@@ -79,7 +79,7 @@ search_client.upsert(collection_name, points)
Once the documents are indexed, you can search for the most relevant documents using the same model with the `retrieval_query` task type:
```python
search_client.search(
client.search(
collection_name=collection_name,
query_vector=mistral_client.embeddings(
model="mistral-embed", input=["What is the best to use for vector search scaling?"]
@@ -30,8 +30,8 @@ output = embed.text(
task_type="search_document",
)
qdrant_client = QdrantClient()
qdrant_client.upsert(
client = QdrantClient()
client.upsert(
collection_name="my-collection",
points=models.Batch(
ids=[1],
@@ -44,14 +44,14 @@ qdrant_client.upsert(
```python
from fastembed import TextEmbedding
from qdrant_client import QdrantClient, models
from client import QdrantClient, models
model = TextEmbedding("nomic-ai/nomic-embed-text-v1")
output = model.embed(["Qdrant is the best vector database!"])
qdrant_client = QdrantClient()
qdrant_client.upsert(
client = QdrantClient()
client.upsert(
collection_name="my-collection",
points=models.Batch(
ids=[1],
@@ -71,7 +71,7 @@ output = embed.text(
task_type="search_query",
)
qdrant_client.search(
client.search(
collection_name="my-collection",
query_vector=output["embeddings"][0],
)
@@ -82,7 +82,7 @@ qdrant_client.search(
```python
output = next(model.embed("What is the best vector database?"))
qdrant_client.search(
client.search(
collection_name="my-collection",
query_vector=output.tolist(),
)
@@ -21,7 +21,7 @@ NVIDIA_API_KEY = "<YOUR_API_KEY>"
nvidia_session = requests.Session()
qdrant_client = QdrantClient(":memory:")
client = QdrantClient(":memory:")
headers = {
"Authorization": f"Bearer {NVIDIA_API_KEY}",
@@ -89,7 +89,7 @@ let response_body = await response.json()
### Converting the model outputs to Qdrant points
```python
from qdrant_client.http.models import PointStruct
from qdrant_client.models import PointStruct
points = [
PointStruct(
@@ -120,14 +120,14 @@ from qdrant_client.models import VectorParams, Distance
collection_name = "example_collection"
qdrant_client.create_collection(
client.create_collection(
collection_name,
vectors_config=VectorParams(
size=1024,
distance=Distance.COSINE,
),
)
qdrant_client.upsert(collection_name, points)
client.upsert(collection_name, points)
```
```typescript
@@ -161,7 +161,7 @@ response_body = nvidia_session.post(
NVIDIA_BASE_URL, headers=headers, json=payload
).json()
qdrant_client.search(
client.search(
collection_name=collection_name,
query_vector=response_body["data"][0]["embedding"],
)
@@ -24,7 +24,7 @@ openai_client = openai.Client(
api_key="<YOUR_API_KEY>"
)
qdrant_client = qdrant_client.QdrantClient(":memory:")
client = qdrant_client.QdrantClient(":memory:")
texts = [
"Qdrant is the best vector search engine!",
@@ -39,13 +39,13 @@ The following example shows how to embed a document with the `text-embedding-3-s
```python
embedding_model = "text-embedding-3-small"
result = openai_client.embeddings.create(input= texts, model=embedding_model)
result = openai_client.embeddings.create(input=texts, model=embedding_model)
```
### Converting the model outputs to Qdrant points
```python
from qdrant_client.http.models import PointStruct
from qdrant_client.models import PointStruct
points = [
PointStruct(
@@ -60,18 +60,18 @@ points = [
### Creating a collection to insert the documents
```python
from qdrant_client.http.models import VectorParams, Distance
from qdrant_client.models import VectorParams, Distance
collection_name = "example_collection"
qdrant_client.create_collection(
client.create_collection(
collection_name,
vectors_config=VectorParams(
size=1536,
distance=Distance.COSINE,
),
)
qdrant_client.upsert(collection_name, points)
client.upsert(collection_name, points)
```
## Searching for documents with Qdrant
@@ -79,7 +79,7 @@ qdrant_client.upsert(collection_name, points)
Once the documents are indexed, you can search for the most relevant documents using the same model.
```python
qdrant_client.search(
client.search(
collection_name=collection_name,
query_vector=openai_client.embeddings.create(
input=["What is the best to use for vector search scaling?"],
@@ -69,7 +69,7 @@ ids = [32, 21, "b626f6a9-b14d-4af9-b7c3-43d8deb719a6"]
payload = [{"meta": "data"}, {"meta": "data_2"}, {"meta": "data_3", "extra": "data"}]
QdrantIngestOperator(
conn_id="qdrant_connection"
conn_id="qdrant_connection",
task_id="qdrant_ingest",
collection_name="<COLLECTION_NAME>",
vectors=vectors,
@@ -68,7 +68,7 @@ assistant = RetrieveAssistantAgent(
# `chunk_token_size` is the chunk token size for the retrieve chat.
# We use an in-memory QdrantClient instance here. Not recommended for production.
ragproxyagent = QdrantRetrieveUserProxyAgent(
rag_proxy_agent = QdrantRetrieveUserProxyAgent(
name="qdrantagent",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,
@@ -95,7 +95,7 @@ assistant.reset()
# The query used below is for demonstration. It should usually be related to the docs made available to the agent
code_problem = "How can I use FLAML to perform a classification task?"
ragproxyagent.initiate_chat(assistant, problem=code_problem)
rag_proxy_agent.initiate_chat(assistant, problem=code_problem)
```
## Next steps
@@ -27,7 +27,7 @@ Scalar Quantization, you'd make that in the following way:
```python
from qdrant_haystack.document_stores import QdrantDocumentStore
from qdrant_client.http import models
from qdrant_client import models
document_store = QdrantDocumentStore(
":memory:",
@@ -68,7 +68,8 @@ client is destroyed - usually at the end of your script/notebook.
```python
qdrant = Qdrant.from_documents(
docs, embeddings,
docs,
embeddings,
location=":memory:", # Local mode with in-memory storage only
collection_name="my_documents",
)
@@ -80,7 +81,8 @@ Local mode, without using the Qdrant server, may also store your vectors on disk
```python
qdrant = Qdrant.from_documents(
docs, embeddings,
docs,
embeddings,
path="/tmp/local_qdrant",
collection_name="my_documents",
)
@@ -62,7 +62,8 @@ from pandasai.ee.vectorstores.qdrant import Qdrant
qdrant = Qdrant(
collection_name="<SOME_COLLECTION>",
embedding_model="sentence-transformers/all-MiniLM-L6-v2",
location="http://localhost:6334",
url="http://localhost:6333",
grpc_port=6334,
prefer_grpc=True
)
@@ -38,7 +38,7 @@ unstructured-ingest \
--verbose \
qdrant \
--collection-name "test" \
--location "http://localhost:6333" \
--url "http://localhost:6333" \
--batch-size 80
```
@@ -66,7 +66,7 @@ from unstructured.ingest.runner.writers.qdrant import QdrantWriter
def get_writer() -> Writer:
return QdrantWriter(
connector_config=SimpleQdrantConfig(
location="http://localhost:6333",
url="http://localhost:6333",
collection_name="test",
),
write_config=QdrantWriteConfig(batch_size=80),
@@ -186,10 +186,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -337,10 +336,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -445,10 +443,9 @@ PUT /collections/{collection_name}/points
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.upsert(
collection_name="{collection_name}",
@@ -662,10 +659,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -913,10 +909,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -1209,7 +1204,7 @@ client.upsert(
[0.1, 0.1, 0.9],
],
),
ordering="strong",
ordering=models.WriteOrdering.STRONG,
)
```
@@ -221,7 +221,7 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -342,7 +342,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -42,10 +42,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -196,10 +195,9 @@ POST /collections/{collection_name}/points/search
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -316,7 +314,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -467,10 +465,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -620,7 +617,7 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -734,7 +731,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -852,7 +849,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -167,10 +167,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -335,10 +334,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -475,10 +473,9 @@ PUT /collections/{collection_name}
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -630,10 +627,9 @@ POST /collections/{collection_name}/points/search
```
```python
from qdrant_client import QdrantClient
from qdrant_client.http import models
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -784,7 +780,7 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -923,7 +919,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -1077,7 +1073,7 @@ POST /collections/{collection_name}/points/search
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.search(
collection_name="{collection_name}",
@@ -1200,7 +1196,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -63,8 +63,7 @@ curl \
from qdrant_client import QdrantClient
client = QdrantClient(
url="https://localhost",
port=6333,
url="https://localhost:6333",
api_key="your_secret_api_key_here",
)
```
@@ -186,8 +185,7 @@ curl -X GET https://localhost:6333
from qdrant_client import QdrantClient
client = QdrantClient(
url="https://localhost",
port=6333,
url="https://localhost:6333",
)
```
@@ -39,7 +39,10 @@ Qdrant is now accessible:
```python
from qdrant_client import QdrantClient
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
```
```typescript
```
```typescript
@@ -78,7 +81,7 @@ var client = new QdrantClient("localhost", 6334);
You will be storing all of your vector data in a Qdrant collection. Let's call it `test_collection`. This collection will be using a dot product distance metric to compare vectors.
```python
from qdrant_client.http.models import Distance, VectorParams
from qdrant_client.models import Distance, VectorParams
client.create_collection(
collection_name="test_collection",
@@ -135,7 +138,7 @@ await client.CreateCollectionAsync(
Let's now add a few vectors with a payload. Payloads are other data you want to associate with the vector:
```python
from qdrant_client.http.models import PointStruct
from qdrant_client.models import PointStruct
operation_info = client.upsert(
collection_name="test_collection",
@@ -524,7 +527,7 @@ See [payload and vector in the result](../concepts/search/#payload-and-vector-in
We can narrow down the results further by filtering by payload. Let's find the closest results that include "London".
```python
from qdrant_client.http.models import Filter, FieldCondition, MatchValue
from qdrant_client.models import Filter, FieldCondition, MatchValue
search_result = client.search(
collection_name="test_collection",
@@ -70,7 +70,7 @@ from aleph_alpha_client import (
from glob import glob
ids, vectors, payloads = [], [], []
async with AsyncClient(token=aa_token) as client:
async with AsyncClient(token=aa_token) as aa_client:
for i, image_path in enumerate(glob("./val2017/*.jpg")):
# Convert the JPEG file into the embedding by calling
# Aleph Alpha API
@@ -82,7 +82,7 @@ async with AsyncClient(token=aa_token) as client:
"compress_to_size": 128,
}
query_request = SemanticEmbeddingRequest(**query_params)
query_response = await client.semantic_embed(request=query_request, model=model)
query_response = await aa_client.semantic_embed(request=query_request, model=model)
# Finally store the id, vector and the payload
ids.append(i)
@@ -96,17 +96,17 @@ Add all created embeddings, along with their ids and payloads into the `COCO` co
```python
import qdrant_client
from qdrant_client.http.models import Batch, VectorParams, Distance
from qdrant_client.models import Batch, VectorParams, Distance
qdrant_client = qdrant_client.QdrantClient()
qdrant_client.recreate_collection(
client = qdrant_client.QdrantClient()
client.recreate_collection(
collection_name="COCO",
vectors_config=VectorParams(
size=len(vectors[0]),
distance=Distance.COSINE,
),
)
qdrant_client.upsert(
client.upsert(
collection_name="COCO",
points=Batch(
ids=ids,
@@ -126,7 +126,7 @@ text queries and reverse image search. Assume you want to find images similar to
With the following code snippet create its vector embedding and then perform the lookup in Qdrant:
```python
async with AsyncCliet(token=aa_token) as client:
async with AsyncCliet(token=aa_token) as aa_client:
prompt = ImagePrompt.from_file("query.jpg")
prompt = Prompt.from_image(prompt)
@@ -136,9 +136,9 @@ async with AsyncCliet(token=aa_token) as client:
"compress_to_size": 128,
}
query_request = SemanticEmbeddingRequest(**query_params)
query_response = await client.semantic_embed(request=query_request, model=model)
query_response = await aa_client.semantic_embed(request=query_request, model=model)
results = qdrant.search(
results = client.search(
collection_name="COCO",
query_vector=query_response.embedding,
limit=3,
@@ -156,16 +156,16 @@ and Spanish. Your search is not only multimodal, but also multilingual, without
```python
text = "Surfing"
async with AsyncClient(token=aa_token) as client:
async with AsyncClient(token=aa_token) as aa_client:
query_params = {
"prompt": Prompt.from_text(text),
"representation": SemanticRepresentation.Symmetric,
"compres_to_size": 128,
}
query_request = SemanticEmbeddingRequest(**query_params)
query_response = await client.semantic_embed(request=query_request, model=model)
query_response = await aa_client.semantic_embed(request=query_request, model=model)
results = qdrant.search(
results = client.search(
collection_name="COCO",
query_vector=query_response.embedding,
limit=3,
@@ -37,7 +37,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -78,7 +78,7 @@ PATCH /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.update_collection(
collection_name="{collection_name}",
@@ -138,7 +138,7 @@ PUT /collections/{collection_name}
```python
from qdrant_client import QdrantClient, models
client = QdrantClient("localhost", port=6333)
client = QdrantClient(url="http://localhost:6333")
client.create_collection(
collection_name="{collection_name}",
@@ -42,11 +42,11 @@ actions to perform.
```python
from qdrant_client import QdrantClient, models
qdrant_client = QdrantClient(
client = QdrantClient(
"https://my-cluster.cloud.qdrant.io:6333",
api_key="my-api-key",
)
qdrant_client.create_collection(
client.create_collection(
collection_name="personal-notes",
vectors_config=models.VectorParams(
size=1024,
@@ -120,7 +120,7 @@ response = cohere_client.embed(
input_type="search_document",
)
qdrant_client.upload_points(
client.upload_points(
collection_name="personal-notes",
points=[
models.PointStruct(
@@ -183,7 +183,7 @@ from typing import Annotated
app = FastAPI()
def qdrant_client() -> QdrantClient:
def client() -> QdrantClient:
return QdrantClient(config.QDRANT_URL, api_key=config.QDRANT_API_KEY)
def cohere_client() -> cohere.Client:
@@ -192,7 +192,7 @@ def cohere_client() -> cohere.Client:
@app.post("/search")
def search(
query: SearchQuery,
qdrant_client: Annotated[QdrantClient, Depends(qdrant_client)],
client: Annotated[QdrantClient, Depends(client)],
cohere_client: Annotated[cohere.Client, Depends(cohere_client)],
) -> SearchResults:
response = cohere_client.embed(
@@ -200,7 +200,7 @@ def search(
model="embed-multilingual-v3.0",
input_type="search_query",
)
results = qdrant_client.search(
results = client.search(
collection_name="personal-notes",
query_vector=response.embeddings[0],
limit=2,
@@ -75,9 +75,9 @@ We used the streaming mode, so the dataset is not loaded into memory. Instead, w
```python
for payload in dataset:
id = payload.pop("id")
id_ = payload.pop("id")
vector = payload.pop("vector")
print(id, vector, payload)
print(id_, vector, payload)
```
A single payload looks like this:
@@ -114,10 +114,10 @@ Calculating the embeddings is usually a bottleneck of the vector search pipeline
```python
ids, vectors, payloads = [], [], []
for payload in dataset:
id = payload.pop("id")
id_ = payload.pop("id")
vector = payload.pop("vector")
ids.append(id)
ids.append(id_)
vectors.append(vector)
payloads.append(payload)
@@ -106,7 +106,7 @@ Now you need to write a script to upload all startup data and vectors into the s
# Import client library
from qdrant_client import QdrantClient
qdrant_client = QdrantClient("http://localhost:6333")
client = QdrantClient("http://localhost:6333")
```
3. Select model to encode your data.
@@ -114,16 +114,16 @@ qdrant_client = QdrantClient("http://localhost:6333")
You will be using a pre-trained model called `sentence-transformers/all-MiniLM-L6-v2`.
```python
qdrant_client.set_model("sentence-transformers/all-MiniLM-L6-v2")
client.set_model("sentence-transformers/all-MiniLM-L6-v2")
```
4. Related vectors need to be added to a collection. Create a new collection for your startup vectors.
```python
qdrant_client.recreate_collection(
client.recreate_collection(
collection_name="startups",
vectors_config=qdrant_client.get_fastembed_vector_params(),
vectors_config=client.get_fastembed_vector_params(),
)
```
@@ -146,13 +146,13 @@ Now you need to write a script to upload all startup data and vectors into the s
from qdrant_client import QdrantClient
from qdrant_client.models import VectorParams, Distance
qdrant_client = QdrantClient("http://localhost:6333")
client = QdrantClient("http://localhost:6333")
```
3. Related vectors need to be added to a collection. Create a new collection for your startup vectors.
```python
qdrant_client.recreate_collection(
client.recreate_collection(
collection_name="startups",
vectors_config=VectorParams(size=384, distance=Distance.COSINE),
)
@@ -186,7 +186,7 @@ vectors = np.load("./startup_vectors.npy")
5. Upload the data
```python
qdrant_client.upload_collection(
client.upload_collection(
collection_name="startups",
vectors=vectors,
payload=payload,
@@ -105,10 +105,10 @@ after receiving the response from the `upsert` endpoint. **As long as the indexi
the exact search**. We have to wait until the indexing is finished to be sure that the approximate search is performed.
```python
client.upload_records(
client.upload_points( # upload_points is available as of qdrant-client v1.7.1
collection_name="arxiv-titles-instructorxl-embeddings",
records=[
models.Record(
points=[
models.PointStruct(
id=item["id"],
vector=item["vector"],
payload=item,
@@ -147,7 +147,7 @@ documents = [
You need to tell Qdrant where to store embeddings. This is a basic demo, so your local computer will use its memory as temporary storage.
```python
qdrant = QdrantClient(":memory:")
client = QdrantClient(":memory:")
```
## 4. Create a collection
@@ -155,7 +155,7 @@ qdrant = QdrantClient(":memory:")
All data in Qdrant is organized by collections. In this case, you are storing books, so we are calling it `my_books`.
```python
qdrant.recreate_collection(
client.recreate_collection(
collection_name="my_books",
vectors_config=models.VectorParams(
size=encoder.get_sentence_embedding_dimension(), # Vector size is defined by used model
@@ -176,7 +176,7 @@ qdrant.recreate_collection(
Tell the database to upload `documents` to the `my_books` collection. This will give each record an id and a payload. The payload is just the metadata from the dataset.
```python
qdrant.upload_points(
client.upload_points(
collection_name="my_books",
points=[
models.PointStruct(
@@ -192,7 +192,7 @@ qdrant.upload_points(
Now that the data is stored in Qdrant, you can ask it questions and receive semantically relevant results.
```python
hits = qdrant.search(
hits = client.search(
collection_name="my_books",
query_vector=encoder.encode("alien invasion").tolist(),
limit=3,
@@ -216,7 +216,7 @@ The search engine shows three of the most likely responses that have to do with
How about the most recent book from the early 2000s?
```python
hits = qdrant.search(
hits = client.search(
collection_name="my_books",
query_vector=encoder.encode("alien invasion").tolist(),
query_filter=models.Filter(