update snippets and descpription

This commit is contained in:
generall
2025-07-15 00:53:26 +02:00
parent 274dec0c25
commit 305e6969d7
9 changed files with 141 additions and 108 deletions
@@ -1 +1,8 @@
This code snippet demonstrates how to use cloud inference in Qdrant Cloud to automatically create vector embeddings from text or image documents during upseart and query operations. This code snippet demonstrates how to use cloud inference in Qdrant Cloud to automatically create vector embeddings from text documents during upseart and query operations.
In this example we create a new point with a new vector, generated on the qdrant cloud side.
`Document` object contains the text which will be used as an input for inference model.
Specific model which should be used for inference is defined in the `model` parameter.
After point is inserted is becomes searchable.
Snippet contains an example of search query request, that uses cloud-side inferene.
`Document` object is used to obtain query vector.
@@ -1,29 +1,29 @@
```bash ```bash
# Create a new vector # Create a new vector
curl -X PUT "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections/<your-collection>/points?wait=true" \\ curl -X PUT "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points?wait=true" \
-H "Content-Type: application/json" \\ -H "Content-Type: application/json" \
-H "api-key: <paste-your-api-key-here>" \\ -H "api-key: <paste-your-api-key-here>" \
-d '{ -d '{
"points": [ "points": [
{ {
"id": 1, "id": 1,
"payload": { "topic": "cooking", "type": "dessert" }, "payload": { "topic": "cooking", "type": "dessert" },
"vector": { "vector": {
"text": "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", "text": "Recipe for baking chocolate chip cookies",
"model": "<the-model-to-use>" "model": "<the-model-to-use>"
} }
} }
] ]
}' }'
# Perform a search query # Perform a search query
curl -X POST "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections/<your-collection>/points/query" \\ curl -X POST "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points/query" \
-H "Content-Type: application/json" \\ -H "Content-Type: application/json" \
-H "api-key: <paste-your-api-key-here>" \\ -H "api-key: <paste-your-api-key-here>" \
-d '{ -d '{
"query": { "query": {
"text": "Recipe for baking chocolate chip cookies", "text": "How to bake cookies?",
"model": "<the-model-to-use>" "model": "<the-model-to-use>"
} }
}' }'
``` ```
@@ -4,7 +4,7 @@ using Qdrant.Client.Grpc;
using Value = Qdrant.Client.Grpc.Value; using Value = Qdrant.Client.Grpc.Value;
var client = new QdrantClient( var client = new QdrantClient(
host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", host: "xyz-example.qdrant.io",
port: 6334, port: 6334,
https: true, https: true,
apiKey: "<paste-your-api-key-here>" apiKey: "<paste-your-api-key-here>"
@@ -16,9 +16,8 @@ await client.UpsertAsync(
new() { new() {
Id = 1, Id = 1,
Vectors = new Document() { Vectors = new Document() {
Text = Text = "Recipe for baking chocolate chip cookies",
"Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", Model = "<the-model-to-use>",
Model = "<the-model-to-use>",
}, },
Payload = { Payload = {
["topic"] = "cooking", ["topic"] = "cooking",
@@ -31,7 +30,8 @@ await client.UpsertAsync(
var points = await client.QueryAsync( var points = await client.QueryAsync(
collectionName: "<your-collection>", collectionName: "<your-collection>",
query: new Document() { query: new Document() {
Text = "Recipe for baking chocolate chip cookies", Model = "<the-model-to-use>" Text = "How to bake cookies?",
Model = "<the-model-to-use>"
} }
); );
@@ -2,58 +2,57 @@
package main package main
import ( import (
"context" "context"
"log" "log"
"time" "time"
"github.com/qdrant/go-client/qdrant" "github.com/qdrant/go-client/qdrant"
) )
func main() { func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
client, err := qdrant.NewClient(&qdrant.Config{ client, err := qdrant.NewClient(&qdrant.Config{
Host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", Host: "xyz-example.qdrant.io",
Port: 6334, Port: 6334,
APIKey: "<paste-your-api-key-here>", APIKey: "<paste-your-api-key-here>",
UseTLS: true, UseTLS: true,
}) })
if err != nil { if err != nil {
log.Fatalf("did not connect: %v", err) log.Fatalf("did not connect: %v", err)
} }
defer client.Close() defer client.Close()
_, err = client.GetPointsClient().Upsert(ctx, &qdrant.UpsertPoints{ _, err = client.GetPointsClient().Upsert(ctx, &qdrant.UpsertPoints{
CollectionName: "<your-collection>", CollectionName: "<your-collection>",
Points: []*qdrant.PointStruct{ Points: []*qdrant.PointStruct{
{ {
Id: qdrant.NewIDNum(uint64(1)), Id: qdrant.NewIDNum(uint64(1)),
Vectors: qdrant.NewVectorsDocument(&qdrant.Document{ Vectors: qdrant.NewVectorsDocument(&qdrant.Document{
Text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", Text: "Recipe for baking chocolate chip cookies",
Model: "<the-model-to-use>", Model: "<the-model-to-use>",
}), }),
Payload: qdrant.NewValueMap(map[string]any{ Payload: qdrant.NewValueMap(map[string]any{
"topic": "cooking", "topic": "cooking",
"type": "dessert", "type": "dessert",
}), }),
}, },
}, },
}) })
if err != nil { if err != nil {
log.Fatalf("error creating point: %v", err) log.Fatalf("error creating point: %v", err)
} }
points, err := client.Query(ctx, &qdrant.QueryPoints{ points, err := client.Query(ctx, &qdrant.QueryPoints{
CollectionName: "<your-collection>", CollectionName: "<your-collection>",
Query: qdrant.NewQueryNearest( Query: qdrant.NewQueryNearest(
qdrant.NewVectorInputDocument(&qdrant.Document{ qdrant.NewVectorInputDocument(&qdrant.Document{
Text: "Recipe for baking chocolate chip cookies", Text: "How to bake cookies?",
Model: "<the-model-to-use>", Model: "<the-model-to-use>",
}), }),
), ),
}) })
log.Printf("List of points: %s", points) log.Printf("List of points: %s", points)
} }
})
``` ```
@@ -0,0 +1,25 @@
```http
# Insert new points with cloud-side inference
PUT /collections/<your-collection>/points?wait=true
{
"points": [
{
"id": 1,
"payload": { "topic": "cooking", "type": "dessert" },
"vector": {
"text": "Recipe for baking chocolate chip cookies",
"model": "<the-model-to-use>"
}
}
]
}
# Search in the collection using cloud-side inference
POST /collections/<your-collection>/points/query
{
"query": {
"text": "How to bake cookies?",
"model": "<the-model-to-use>"
}
}
```
@@ -14,10 +14,11 @@ import java.util.Map;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
public class Main { public class Main {
public static void main(String[] args) throws ExecutionException, InterruptedException { public static void main(String[] args)
throws ExecutionException, InterruptedException {
QdrantClient client = QdrantClient client =
new QdrantClient( new QdrantClient(
QdrantGrpcClient.newBuilder("xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", 6334, true) QdrantGrpcClient.newBuilder("xyz-example.qdrant.io", 6334, true)
.withApiKey("<paste-your-api-key-here>") .withApiKey("<paste-your-api-key-here>")
.build()); .build());
@@ -30,8 +31,7 @@ public class Main {
.setVectors( .setVectors(
vectors( vectors(
Document.newBuilder() Document.newBuilder()
.setText( .setText("Recipe for baking chocolate chip cookies")
"Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.")
.setModel("<the-model-to-use>") .setModel("<the-model-to-use>")
.build())) .build()))
.putAllPayload(Map.of("topic", value("cooking"), "type", value("dessert"))) .putAllPayload(Map.of("topic", value("cooking"), "type", value("dessert")))
@@ -46,7 +46,7 @@ public class Main {
.setQuery( .setQuery(
nearest( nearest(
Document.newBuilder() Document.newBuilder()
.setText("Recipe for baking chocolate chip cookies") .setText("How to bake cookies?")
.setModel("<the-model-to-use>") .setModel("<the-model-to-use>")
.build())) .build()))
.build()) .build())
@@ -1,10 +1,12 @@
```python ```python
from qdrant_client import QdrantClient from qdrant_client import QdrantClient
from qdrant_client.http.models import PointStruct, Document from qdrant_client.models import PointStruct, Document
client = QdrantClient( client = QdrantClient(
url="https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333", url="https://xyz-example.qdrant.io:6333",
api_key="<paste-your-api-key-here>", api_key="<paste-your-api-key-here>",
# IMPORTANT
# If not enabled, inference will be performed locally
cloud_inference=True, cloud_inference=True,
) )
@@ -13,7 +15,7 @@ points = [
id=1, id=1,
payload={"topic": "cooking", "type": "dessert"}, payload={"topic": "cooking", "type": "dessert"},
vector=Document( vector=Document(
text="Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", text="Recipe for baking chocolate chip cookies",
model="<the-model-to-use>" model="<the-model-to-use>"
) )
) )
@@ -21,10 +23,13 @@ points = [
client.upsert(collection_name="<your-collection>", points=points) client.upsert(collection_name="<your-collection>", points=points)
points = client.query_points(collection_name="<your-collection>", query=Document( result = client.query_points(
text="Recipe for baking chocolate chip cookies requires flour", collection_name="<your-collection>",
model="<the-model-to-use>" query=Document(
)) text="How to bake cookies?",
model="<the-model-to-use>"
)
)
print(points) print(result)
``` ```
@@ -1,9 +1,6 @@
```rust ```rust
use qdrant_client::qdrant::vector; use qdrant_client::qdrant::Query;
use qdrant_client::qdrant::vector_input;
use qdrant_client::qdrant::QueryPointsBuilder; use qdrant_client::qdrant::QueryPointsBuilder;
use qdrant_client::qdrant::Vector;
use qdrant_client::qdrant::VectorInput;
use qdrant_client::Payload; use qdrant_client::Payload;
use qdrant_client::Qdrant; use qdrant_client::Qdrant;
use qdrant_client::qdrant::{Document}; use qdrant_client::qdrant::{Document};
@@ -11,40 +8,40 @@ use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder};
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let client = Qdrant::from_url("https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6334") let client = Qdrant::from_url("https://xyz-example.qdrant.io:6334")
.api_key("<paste-your-api-key-here>") .api_key("<paste-your-api-key-here>")
.build() .build()
.unwrap(); .unwrap();
let mut points = Vec::new(); let points = vec![
PointStruct::new(
1,
Document::new(
"Recipe for baking chocolate chip cookies",
"<the-model-to-use>"
),
Payload::try_from(serde_json::json!(
{"topic": "cooking", "type": "dessert"}
)).unwrap(),
)
];
let vector = Vector { let upsert_request = UpsertPointsBuilder::new(
vector: Some(vector::Vector::Document(Document { "<your-collection>",
text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.".to_string(), points
model: "<the-model-to-use>".to_string(), ).wait(true);
options: Default::default(),
})),
..Default::default()
};
points.push(PointStruct::new(1, vector, Payload::default())); let _ = client.upsert_points(upsert_request).await;
let _ = client let query_document = Document::new(
.upsert_points(UpsertPointsBuilder::new("<your-collection>", points).wait(true)) "How to bake cookies?",
.await; "<the-model-to-use>"
);
let document = Document { let query_request = QueryPointsBuilder::new("<your-collection>")
text: "Recipe for baking chocolate chip cookies".to_string(), .query(Query::new_nearest(query_document));
model: "<the-model-to-use>".to_string(),
options: Default::default(),
};
let query = VectorInput {
variant: Some(vector_input::Variant::Document(document)),
};
let query_request = QueryPointsBuilder::new("<your-collection>").query(query);
let result = client.query(query_request).await.unwrap(); let result = client.query(query_request).await.unwrap();
println!("Result: {:?}", result); println!("Result: {:?}", result);
}
``` ```
@@ -2,7 +2,7 @@
import {QdrantClient} from "@qdrant/js-client-rest"; import {QdrantClient} from "@qdrant/js-client-rest";
const client = new QdrantClient({ const client = new QdrantClient({
url: 'https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333', url: 'https://xyz-example.qdrant.io:6333',
apiKey: '<paste-your-api-key-here>', apiKey: '<paste-your-api-key-here>',
}); });
@@ -11,7 +11,7 @@ const points = [
id: 1, id: 1,
payload: { topic: "cooking", type: "dessert" }, payload: { topic: "cooking", type: "dessert" },
vector: { vector: {
text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", text: "Recipe for baking chocolate chip cookies",
model: "<the-model-to-use>" model: "<the-model-to-use>"
} }
} }
@@ -23,7 +23,7 @@ const result = await client.query(
"<your-collection>", "<your-collection>",
{ {
query: { query: {
text: "What ingredients are needed for baking chocolate chip cookies?", text: "How to bake cookies?",
model: "<the-model-to-use>" model: "<the-model-to-use>"
}, },
} }