Cloud inference example (#1768)

* Cloud inference example

* Cloud inference example

* update URL

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Update qdrant-landing/content/documentation/examples/cloud-inference-hybrid-search.md

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>

* Move cloud inference tutorial

* move below support

* rename folder

* update cloud example

* update cloud example

* update cloud example

* update cloud example

* update cloud example

* update cloud example

* update cloud example

* update cloud example

* Link inference docs

* Link inference docs

* Create collection snippet

* Create snippets

* Create snippets

* Create snippets

* Create snippets

* Create snippets

* Create snippets

* Create snippets

* Create snippets

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/upload-data/python.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/tutorials-and-examples/cloud-inference-hybrid-search.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/tutorials-and-examples/_index.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/upload-data/python.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/tutorials-and-examples/cloud-inference-hybrid-search.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/run-vector-search/python.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/tutorials-and-examples/cloud-inference-hybrid-search.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/initialize-client/_description.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/run-vector-search/_description.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/create-sample-query/python.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/headless/snippets/cloud-inference/vector-search/create-collection/python.md

Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>

* Update qdrant-landing/content/documentation/tutorials-and-examples/cloud-inference-hybrid-search.md

---------

Co-authored-by: Bastian Hofmann <mail@bastianhofmann.de>
Co-authored-by: Kacper Łukawski <kacperlukawski@users.noreply.github.com>
This commit is contained in:
Derrick Mwiti
2025-07-15 14:08:37 +03:00
committed by GitHub
co-authored by Bastian Hofmann Kacper Łukawski
parent b40514678f
commit 5eff7dfc24
13 changed files with 169 additions and 1 deletions
@@ -0,0 +1 @@
This code snippet creates a collection configured for hybrid search using Qdrant's Cloud Inference. It defines a sparse BM25 vector and a dense vector for MiniLM. This setup allows Qdrant to perform hybrid search using the dense and sparse vectors.
@@ -0,0 +1,21 @@
```python
from qdrant_client import models
collection_name = "my_collection_name"
if not client.collection_exists(collection_name=collection_name):
client.create_collection(
collection_name=collection_name,
vectors_config={
"dense_vector": models.VectorParams(
size=384,
distance=models.Distance.COSINE
)
},
sparse_vectors_config={
"bm25_sparse_vector": models.SparseVectorParams(
modifier=models.Modifier.IDF # Enable Inverse Document Frequency
)
}
)
```
@@ -0,0 +1 @@
This code snippet creates sample query for hybrid search using Qdrant's cloud inference.
@@ -0,0 +1,3 @@
```python
query_text = "What is relapsing polychondritis?"
```
@@ -0,0 +1 @@
This code snippet connects to Qdrant Cloud with Cloud Inference enabled. This is done by setting `cloud_inference` to `True` in the initializer of the `QdrantClient` class.
@@ -0,0 +1,8 @@
```python
client = QdrantClient(
url="https://YOUR_URL.eastus-0.azure.cloud.qdrant.io:6333/",
api_key="YOUR_API_KEY",
cloud_inference=True,
timeout=30.0
)
```
@@ -0,0 +1 @@
This code snippet demonstrates how to use the Universal Query API to prefetch results with dense and sparse vector search, and then rerank them with Reciprocal Rank Fusion. It uses Cloud Inference to create embeddings by passing document text along with the model names, instead of vectors.
@@ -0,0 +1,28 @@
```python
results = client.query_points(
collection_name=collection_name,
prefetch=[
models.Prefetch(
query=Document(
text=query_text,
model=dense_model
),
using="dense_vector",
limit=5
),
models.Prefetch(
query=Document(
text=query_text,
model=bm25_model
),
using="bm25_sparse_vector",
limit=5
)
],
query=models.FusionQuery(fusion=models.Fusion.RRF),
limit=5,
with_payload=True
)
print(results.points)
```
@@ -0,0 +1 @@
This code snipet shows how to load a dataset and upload dense and sparse vectors to Qdrant. While uploading the vectors we also include a payload known as text.
@@ -0,0 +1,38 @@
```python
from qdrant_client.http.models import PointStruct, Document
from datasets import load_dataset
import uuid
dense_model = "sentence-transformers/all-minilm-l6-v2"
bm25_model = "qdrant/bm25"
ds = load_dataset("miriad/miriad-4.4M", split="train[0:100]")
points = []
for idx, item in enumerate(ds):
passage = item["passage_text"]
point = PointStruct(
id=uuid.uuid4().hex, # use unique string ID
payload=item,
vector={
"dense_vector": Document(
text=passage,
model=dense_model
),
"bm25_sparse_vector": Document(
text=passage,
model=bm25_model
)
}
)
points.append(point)
client.upload_points(
collection_name=collection_name,
points=points,
batch_size=8
)
```