From 6cac0e2e79250bf2f4eaa83564f49e3a0f5126e4 Mon Sep 17 00:00:00 2001 From: Bastian Hofmann Date: Mon, 14 Jul 2025 16:56:53 +0200 Subject: [PATCH] Extract code examples into snippets --- .../content/documentation/cloud/inference.md | 307 +----------------- .../cloud-inference/simple/_description.md | 1 + .../snippets/cloud-inference/simple/bash.md | 29 ++ .../snippets/cloud-inference/simple/csharp.md | 41 +++ .../snippets/cloud-inference/simple/go.md | 59 ++++ .../snippets/cloud-inference/simple/java.md | 58 ++++ .../snippets/cloud-inference/simple/python.md | 30 ++ .../snippets/cloud-inference/simple/rust.md | 50 +++ .../cloud-inference/simple/typescript.md | 33 ++ 9 files changed, 302 insertions(+), 306 deletions(-) create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/_description.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/bash.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/csharp.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/go.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/java.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/python.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/rust.md create mode 100644 qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/typescript.md diff --git a/qdrant-landing/content/documentation/cloud/inference.md b/qdrant-landing/content/documentation/cloud/inference.md index e73ea517b..00b71cce4 100644 --- a/qdrant-landing/content/documentation/cloud/inference.md +++ b/qdrant-landing/content/documentation/cloud/inference.md @@ -31,312 +31,7 @@ Inference is billed based on the number of tokens processed by the model. The co Inference can be easily used through the Qdrant SDKs and the REST or GRPC APIs. Inference is available when upserting points as well as when querying the database. -```bash -# Create a new vector -curl -X PUT "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections//points?wait=true" \\ - -H "Content-Type: application/json" \\ - -H "api-key: " \\ - -d '{ - "points": [ - { - "id": 1, - "payload": { "topic": "cooking", "type": "dessert" }, - "vector": { - "text": "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", - "model": "" - } - } - ] - }' - -# Perform a search query -curl -X POST "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections//points/query" \\ - -H "Content-Type: application/json" \\ - -H "api-key: " \\ - -d '{ - "query": { - "text": "Recipe for baking chocolate chip cookies", - "model": "" - } - }' -``` - -```python -from qdrant_client import QdrantClient -from qdrant_client.http.models import PointStruct, Document - -client = QdrantClient( - url="https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333", - api_key="", - cloud_inference=True, -) - -points = [ - PointStruct( - id=1, - payload={"topic": "cooking", "type": "dessert"}, - vector=Document( - text="Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", - model="" - ) - ) -] - -client.upsert(collection_name="", points=points) - -points = client.query_points(collection_name="", query=Document( - text="Recipe for baking chocolate chip cookies requires flour", - model="" -)) - -print(points) -``` - -```typescript -import {QdrantClient} from "@qdrant/js-client-rest"; - -const client = new QdrantClient({ - url: 'https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333', - apiKey: '', -}); - -const points = [ - { - id: 1, - payload: { topic: "cooking", type: "dessert" }, - vector: { - text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", - model: "" - } - } -]; - -await client.upsert("", { wait: true, points }); - -const result = await client.query( - "", - { - query: { - text: "What ingredients are needed for baking chocolate chip cookies?", - model: "" - }, - } -) - -console.log(result); -``` - -```rust -use qdrant_client::qdrant::vector; -use qdrant_client::qdrant::vector_input; -use qdrant_client::qdrant::QueryPointsBuilder; -use qdrant_client::qdrant::Vector; -use qdrant_client::qdrant::VectorInput; -use qdrant_client::Payload; -use qdrant_client::Qdrant; -use qdrant_client::qdrant::{Document}; -use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder}; - -#[tokio::main] -async fn main() { - let client = Qdrant::from_url("https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6334") - .api_key("") - .build() - .unwrap(); - - let mut points = Vec::new(); - - let vector = Vector { - vector: Some(vector::Vector::Document(Document { - text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.".to_string(), - model: "".to_string(), - options: Default::default(), - })), - ..Default::default() - }; - - points.push(PointStruct::new(1, vector, Payload::default())); - - let _ = client - .upsert_points(UpsertPointsBuilder::new("", points).wait(true)) - .await; - - let document = Document { - text: "Recipe for baking chocolate chip cookies".to_string(), - model: "".to_string(), - options: Default::default(), - }; - - let query = VectorInput { - variant: Some(vector_input::Variant::Document(document)), - }; - - let query_request = QueryPointsBuilder::new("").query(query); - - let result = client.query(query_request).await.unwrap(); - println!("Result: {:?}", result); -``` - -```java -package org.example; - -import static io.qdrant.client.PointIdFactory.id; -import static io.qdrant.client.QueryFactory.nearest; -import static io.qdrant.client.ValueFactory.value; -import static io.qdrant.client.VectorsFactory.vectors; - -import io.qdrant.client.grpc.Points; -import io.qdrant.client.grpc.Points.Document; -import io.qdrant.client.grpc.Points.PointStruct; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ExecutionException; - -public class Main { - public static void main(String[] args) throws ExecutionException, InterruptedException { - QdrantClient client = - new QdrantClient( - QdrantGrpcClient.newBuilder("xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", 6334, true) - .withApiKey("") - .build()); - - client - .upsertAsync( - "", - List.of( - PointStruct.newBuilder() - .setId(id(1)) - .setVectors( - vectors( - Document.newBuilder() - .setText( - "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.") - .setModel("") - .build())) - .putAllPayload(Map.of("topic", value("cooking"), "type", value("dessert"))) - .build())) - .get(); - - List points = - client - .queryAsync( - Points.QueryPoints.newBuilder() - .setCollectionName("") - .setQuery( - nearest( - Document.newBuilder() - .setText("Recipe for baking chocolate chip cookies") - .setModel("") - .build())) - .build()) - .get(); - - System.out.printf(points.toString()); - } -} -``` - -```csharp -using Qdrant.Client; -using Qdrant.Client.Grpc; -using Value = Qdrant.Client.Grpc.Value; - -var client = new QdrantClient( - host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", - port: 6334, - https: true, - apiKey: "" -); - -await client.UpsertAsync( - collectionName: "", - points: new List { - new() { - Id = 1, - Vectors = new Document() { - Text = - "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", - Model = "", - }, - Payload = { - ["topic"] = "cooking", - ["type"] = "dessert" - }, - }, - } -); - -var points = await client.QueryAsync( - collectionName: "", - query: new Document() { - Text = "Recipe for baking chocolate chip cookies", Model = "" - } -); - -foreach(var point in points) { - Console.WriteLine(point); -} -``` - -```go -package main - -import ( - "context" - "log" - "time" - - "github.com/qdrant/go-client/qdrant" -) - -func main() { - ctx, cancel := context.WithTimeout(context.Background(), time.Second) - defer cancel() - - client, err := qdrant.NewClient(&qdrant.Config{ - Host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", - Port: 6334, - APIKey: "", - UseTLS: true, - }) - if err != nil { - log.Fatalf("did not connect: %v", err) - } - defer client.Close() - - _, err = client.GetPointsClient().Upsert(ctx, &qdrant.UpsertPoints{ - CollectionName: "", - Points: []*qdrant.PointStruct{ - { - Id: qdrant.NewIDNum(uint64(1)), - Vectors: qdrant.NewVectorsDocument(&qdrant.Document{ - Text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", - Model: "", - }), - Payload: qdrant.NewValueMap(map[string]any{ - "topic": "cooking", - "type": "dessert", - }), - }, - }, - }) - if err != nil { - log.Fatalf("error creating point: %v", err) - } - - points, err := client.Query(ctx, &qdrant.QueryPoints{ - CollectionName: "", - Query: qdrant.NewQueryNearest( - qdrant.NewVectorInputDocument(&qdrant.Document{ - Text: "Recipe for baking chocolate chip cookies", - Model: "", - }), - ), - }) - log.Printf("List of points: %s", points) -} -}) -``` +{{< code-snippet path="/documentation/headless/snippets/cloud-inference/simple/" >}} Usage examples, specific to each cluster and model, can also be found in the Inference tab of the Cluster Detail page in the Qdrant Cloud Console. diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/_description.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/_description.md new file mode 100644 index 000000000..f215289a3 --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/_description.md @@ -0,0 +1 @@ +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. \ No newline at end of file diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/bash.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/bash.md new file mode 100644 index 000000000..a5e8c7fbf --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/bash.md @@ -0,0 +1,29 @@ +```bash +# Create a new vector +curl -X PUT "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections//points?wait=true" \\ + -H "Content-Type: application/json" \\ + -H "api-key: " \\ + -d '{ + "points": [ + { + "id": 1, + "payload": { "topic": "cooking", "type": "dessert" }, + "vector": { + "text": "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", + "model": "" + } + } + ] + }' + +# Perform a search query +curl -X POST "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections//points/query" \\ + -H "Content-Type: application/json" \\ + -H "api-key: " \\ + -d '{ + "query": { + "text": "Recipe for baking chocolate chip cookies", + "model": "" + } + }' +``` diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/csharp.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/csharp.md new file mode 100644 index 000000000..05d47edbf --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/csharp.md @@ -0,0 +1,41 @@ +```csharp +using Qdrant.Client; +using Qdrant.Client.Grpc; +using Value = Qdrant.Client.Grpc.Value; + +var client = new QdrantClient( + host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", + port: 6334, + https: true, + apiKey: "" +); + +await client.UpsertAsync( + collectionName: "", + points: new List { + new() { + Id = 1, + Vectors = new Document() { + Text = + "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", + Model = "", + }, + Payload = { + ["topic"] = "cooking", + ["type"] = "dessert" + }, + }, + } +); + +var points = await client.QueryAsync( + collectionName: "", + query: new Document() { + Text = "Recipe for baking chocolate chip cookies", Model = "" + } +); + +foreach(var point in points) { + Console.WriteLine(point); +} +``` diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/go.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/go.md new file mode 100644 index 000000000..c632457d5 --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/go.md @@ -0,0 +1,59 @@ +```go +package main + +import ( + "context" + "log" + "time" + + "github.com/qdrant/go-client/qdrant" +) + +func main() { + ctx, cancel := context.WithTimeout(context.Background(), time.Second) + defer cancel() + + client, err := qdrant.NewClient(&qdrant.Config{ + Host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", + Port: 6334, + APIKey: "", + UseTLS: true, + }) + if err != nil { + log.Fatalf("did not connect: %v", err) + } + defer client.Close() + + _, err = client.GetPointsClient().Upsert(ctx, &qdrant.UpsertPoints{ + CollectionName: "", + Points: []*qdrant.PointStruct{ + { + Id: qdrant.NewIDNum(uint64(1)), + Vectors: qdrant.NewVectorsDocument(&qdrant.Document{ + Text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", + Model: "", + }), + Payload: qdrant.NewValueMap(map[string]any{ + "topic": "cooking", + "type": "dessert", + }), + }, + }, + }) + if err != nil { + log.Fatalf("error creating point: %v", err) + } + + points, err := client.Query(ctx, &qdrant.QueryPoints{ + CollectionName: "", + Query: qdrant.NewQueryNearest( + qdrant.NewVectorInputDocument(&qdrant.Document{ + Text: "Recipe for baking chocolate chip cookies", + Model: "", + }), + ), + }) + log.Printf("List of points: %s", points) +} +}) +``` diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/java.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/java.md new file mode 100644 index 000000000..18e3b32d9 --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/java.md @@ -0,0 +1,58 @@ +```java +package org.example; + +import static io.qdrant.client.PointIdFactory.id; +import static io.qdrant.client.QueryFactory.nearest; +import static io.qdrant.client.ValueFactory.value; +import static io.qdrant.client.VectorsFactory.vectors; + +import io.qdrant.client.grpc.Points; +import io.qdrant.client.grpc.Points.Document; +import io.qdrant.client.grpc.Points.PointStruct; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ExecutionException; + +public class Main { + public static void main(String[] args) throws ExecutionException, InterruptedException { + QdrantClient client = + new QdrantClient( + QdrantGrpcClient.newBuilder("xyz-example.cloud-region.cloud-provider.cloud.qdrant.io", 6334, true) + .withApiKey("") + .build()); + + client + .upsertAsync( + "", + List.of( + PointStruct.newBuilder() + .setId(id(1)) + .setVectors( + vectors( + Document.newBuilder() + .setText( + "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.") + .setModel("") + .build())) + .putAllPayload(Map.of("topic", value("cooking"), "type", value("dessert"))) + .build())) + .get(); + + List points = + client + .queryAsync( + Points.QueryPoints.newBuilder() + .setCollectionName("") + .setQuery( + nearest( + Document.newBuilder() + .setText("Recipe for baking chocolate chip cookies") + .setModel("") + .build())) + .build()) + .get(); + + System.out.printf(points.toString()); + } +} +``` diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/python.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/python.md new file mode 100644 index 000000000..c54753986 --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/python.md @@ -0,0 +1,30 @@ +```python +from qdrant_client import QdrantClient +from qdrant_client.http.models import PointStruct, Document + +client = QdrantClient( + url="https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333", + api_key="", + cloud_inference=True, +) + +points = [ + PointStruct( + id=1, + payload={"topic": "cooking", "type": "dessert"}, + vector=Document( + text="Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", + model="" + ) + ) +] + +client.upsert(collection_name="", points=points) + +points = client.query_points(collection_name="", query=Document( + text="Recipe for baking chocolate chip cookies requires flour", + model="" +)) + +print(points) +``` diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/rust.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/rust.md new file mode 100644 index 000000000..8bb72b329 --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/rust.md @@ -0,0 +1,50 @@ +```rust +use qdrant_client::qdrant::vector; +use qdrant_client::qdrant::vector_input; +use qdrant_client::qdrant::QueryPointsBuilder; +use qdrant_client::qdrant::Vector; +use qdrant_client::qdrant::VectorInput; +use qdrant_client::Payload; +use qdrant_client::Qdrant; +use qdrant_client::qdrant::{Document}; +use qdrant_client::qdrant::{PointStruct, UpsertPointsBuilder}; + +#[tokio::main] +async fn main() { + let client = Qdrant::from_url("https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6334") + .api_key("") + .build() + .unwrap(); + + let mut points = Vec::new(); + + let vector = Vector { + vector: Some(vector::Vector::Document(Document { + text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.".to_string(), + model: "".to_string(), + options: Default::default(), + })), + ..Default::default() + }; + + points.push(PointStruct::new(1, vector, Payload::default())); + + let _ = client + .upsert_points(UpsertPointsBuilder::new("", points).wait(true)) + .await; + + let document = Document { + text: "Recipe for baking chocolate chip cookies".to_string(), + model: "".to_string(), + options: Default::default(), + }; + + let query = VectorInput { + variant: Some(vector_input::Variant::Document(document)), + }; + + let query_request = QueryPointsBuilder::new("").query(query); + + let result = client.query(query_request).await.unwrap(); + println!("Result: {:?}", result); +``` diff --git a/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/typescript.md b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/typescript.md new file mode 100644 index 000000000..7affa5d8c --- /dev/null +++ b/qdrant-landing/content/documentation/headless/snippets/cloud-inference/simple/typescript.md @@ -0,0 +1,33 @@ +```typescript +import {QdrantClient} from "@qdrant/js-client-rest"; + +const client = new QdrantClient({ + url: 'https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333', + apiKey: '', +}); + +const points = [ + { + id: 1, + payload: { topic: "cooking", type: "dessert" }, + vector: { + text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.", + model: "" + } + } +]; + +await client.upsert("", { wait: true, points }); + +const result = await client.query( + "", + { + query: { + text: "What ingredients are needed for baking chocolate chip cookies?", + model: "" + }, + } +) + +console.log(result); +```