mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-09 21:08:31 +02:00
update snippets and descpription
This commit is contained in:
+8
-1
@@ -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.
|
||||
|
||||
+11
-11
@@ -1,29 +1,29 @@
|
||||
```bash
|
||||
# Create a new vector
|
||||
curl -X PUT "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections/<your-collection>/points?wait=true" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "api-key: <paste-your-api-key-here>" \\
|
||||
# Create a new vector
|
||||
curl -X PUT "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points?wait=true" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: <paste-your-api-key-here>" \
|
||||
-d '{
|
||||
"points": [
|
||||
{
|
||||
"id": 1,
|
||||
"payload": { "topic": "cooking", "type": "dessert" },
|
||||
"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>"
|
||||
}
|
||||
}
|
||||
]
|
||||
}'
|
||||
|
||||
|
||||
# Perform a search query
|
||||
curl -X POST "https://xyz-example.cloud-region.cloud-provider.cloud.qdrant.io:6333/collections/<your-collection>/points/query" \\
|
||||
-H "Content-Type: application/json" \\
|
||||
-H "api-key: <paste-your-api-key-here>" \\
|
||||
curl -X POST "https://xyz-example.qdrant.io:6333/collections/<your-collection>/points/query" \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "api-key: <paste-your-api-key-here>" \
|
||||
-d '{
|
||||
"query": {
|
||||
"text": "Recipe for baking chocolate chip cookies",
|
||||
"text": "How to bake cookies?",
|
||||
"model": "<the-model-to-use>"
|
||||
}
|
||||
}'
|
||||
}'
|
||||
```
|
||||
|
||||
+5
-5
@@ -4,7 +4,7 @@ using Qdrant.Client.Grpc;
|
||||
using Value = Qdrant.Client.Grpc.Value;
|
||||
|
||||
var client = new QdrantClient(
|
||||
host: "xyz-example.cloud-region.cloud-provider.cloud.qdrant.io",
|
||||
host: "xyz-example.qdrant.io",
|
||||
port: 6334,
|
||||
https: true,
|
||||
apiKey: "<paste-your-api-key-here>"
|
||||
@@ -16,9 +16,8 @@ await client.UpsertAsync(
|
||||
new() {
|
||||
Id = 1,
|
||||
Vectors = new Document() {
|
||||
Text =
|
||||
"Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.",
|
||||
Model = "<the-model-to-use>",
|
||||
Text = "Recipe for baking chocolate chip cookies",
|
||||
Model = "<the-model-to-use>",
|
||||
},
|
||||
Payload = {
|
||||
["topic"] = "cooking",
|
||||
@@ -31,7 +30,8 @@ await client.UpsertAsync(
|
||||
var points = await client.QueryAsync(
|
||||
collectionName: "<your-collection>",
|
||||
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>"
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
+45
-46
@@ -2,58 +2,57 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
"context"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
"github.com/qdrant/go-client/qdrant"
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
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: "<paste-your-api-key-here>",
|
||||
UseTLS: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
defer client.Close()
|
||||
client, err := qdrant.NewClient(&qdrant.Config{
|
||||
Host: "xyz-example.qdrant.io",
|
||||
Port: 6334,
|
||||
APIKey: "<paste-your-api-key-here>",
|
||||
UseTLS: true,
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("did not connect: %v", err)
|
||||
}
|
||||
defer client.Close()
|
||||
|
||||
_, err = client.GetPointsClient().Upsert(ctx, &qdrant.UpsertPoints{
|
||||
CollectionName: "<your-collection>",
|
||||
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: "<the-model-to-use>",
|
||||
}),
|
||||
Payload: qdrant.NewValueMap(map[string]any{
|
||||
"topic": "cooking",
|
||||
"type": "dessert",
|
||||
}),
|
||||
},
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("error creating point: %v", err)
|
||||
}
|
||||
_, err = client.GetPointsClient().Upsert(ctx, &qdrant.UpsertPoints{
|
||||
CollectionName: "<your-collection>",
|
||||
Points: []*qdrant.PointStruct{
|
||||
{
|
||||
Id: qdrant.NewIDNum(uint64(1)),
|
||||
Vectors: qdrant.NewVectorsDocument(&qdrant.Document{
|
||||
Text: "Recipe for baking chocolate chip cookies",
|
||||
Model: "<the-model-to-use>",
|
||||
}),
|
||||
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: "<your-collection>",
|
||||
Query: qdrant.NewQueryNearest(
|
||||
qdrant.NewVectorInputDocument(&qdrant.Document{
|
||||
Text: "Recipe for baking chocolate chip cookies",
|
||||
Model: "<the-model-to-use>",
|
||||
}),
|
||||
),
|
||||
})
|
||||
log.Printf("List of points: %s", points)
|
||||
points, err := client.Query(ctx, &qdrant.QueryPoints{
|
||||
CollectionName: "<your-collection>",
|
||||
Query: qdrant.NewQueryNearest(
|
||||
qdrant.NewVectorInputDocument(&qdrant.Document{
|
||||
Text: "How to bake cookies?",
|
||||
Model: "<the-model-to-use>",
|
||||
}),
|
||||
),
|
||||
})
|
||||
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>"
|
||||
}
|
||||
}
|
||||
```
|
||||
+5
-5
@@ -14,10 +14,11 @@ import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws ExecutionException, InterruptedException {
|
||||
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)
|
||||
QdrantGrpcClient.newBuilder("xyz-example.qdrant.io", 6334, true)
|
||||
.withApiKey("<paste-your-api-key-here>")
|
||||
.build());
|
||||
|
||||
@@ -30,8 +31,7 @@ public class Main {
|
||||
.setVectors(
|
||||
vectors(
|
||||
Document.newBuilder()
|
||||
.setText(
|
||||
"Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.")
|
||||
.setText("Recipe for baking chocolate chip cookies")
|
||||
.setModel("<the-model-to-use>")
|
||||
.build()))
|
||||
.putAllPayload(Map.of("topic", value("cooking"), "type", value("dessert")))
|
||||
@@ -46,7 +46,7 @@ public class Main {
|
||||
.setQuery(
|
||||
nearest(
|
||||
Document.newBuilder()
|
||||
.setText("Recipe for baking chocolate chip cookies")
|
||||
.setText("How to bake cookies?")
|
||||
.setModel("<the-model-to-use>")
|
||||
.build()))
|
||||
.build())
|
||||
|
||||
+13
-8
@@ -1,10 +1,12 @@
|
||||
```python
|
||||
from qdrant_client import QdrantClient
|
||||
from qdrant_client.http.models import PointStruct, Document
|
||||
from qdrant_client.models import PointStruct, Document
|
||||
|
||||
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>",
|
||||
# IMPORTANT
|
||||
# If not enabled, inference will be performed locally
|
||||
cloud_inference=True,
|
||||
)
|
||||
|
||||
@@ -13,7 +15,7 @@ points = [
|
||||
id=1,
|
||||
payload={"topic": "cooking", "type": "dessert"},
|
||||
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>"
|
||||
)
|
||||
)
|
||||
@@ -21,10 +23,13 @@ points = [
|
||||
|
||||
client.upsert(collection_name="<your-collection>", points=points)
|
||||
|
||||
points = client.query_points(collection_name="<your-collection>", query=Document(
|
||||
text="Recipe for baking chocolate chip cookies requires flour",
|
||||
model="<the-model-to-use>"
|
||||
))
|
||||
result = client.query_points(
|
||||
collection_name="<your-collection>",
|
||||
query=Document(
|
||||
text="How to bake cookies?",
|
||||
model="<the-model-to-use>"
|
||||
)
|
||||
)
|
||||
|
||||
print(points)
|
||||
print(result)
|
||||
```
|
||||
|
||||
+26
-29
@@ -1,9 +1,6 @@
|
||||
```rust
|
||||
use qdrant_client::qdrant::vector;
|
||||
use qdrant_client::qdrant::vector_input;
|
||||
use qdrant_client::qdrant::Query;
|
||||
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};
|
||||
@@ -11,40 +8,40 @@ 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")
|
||||
let client = Qdrant::from_url("https://xyz-example.qdrant.io:6334")
|
||||
.api_key("<paste-your-api-key-here>")
|
||||
.build()
|
||||
.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 {
|
||||
vector: Some(vector::Vector::Document(Document {
|
||||
text: "Recipe for baking chocolate chip cookies requires flour, sugar, eggs, and chocolate chips.".to_string(),
|
||||
model: "<the-model-to-use>".to_string(),
|
||||
options: Default::default(),
|
||||
})),
|
||||
..Default::default()
|
||||
};
|
||||
let upsert_request = UpsertPointsBuilder::new(
|
||||
"<your-collection>",
|
||||
points
|
||||
).wait(true);
|
||||
|
||||
points.push(PointStruct::new(1, vector, Payload::default()));
|
||||
let _ = client.upsert_points(upsert_request).await;
|
||||
|
||||
let _ = client
|
||||
.upsert_points(UpsertPointsBuilder::new("<your-collection>", points).wait(true))
|
||||
.await;
|
||||
let query_document = Document::new(
|
||||
"How to bake cookies?",
|
||||
"<the-model-to-use>"
|
||||
);
|
||||
|
||||
let document = Document {
|
||||
text: "Recipe for baking chocolate chip cookies".to_string(),
|
||||
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 query_request = QueryPointsBuilder::new("<your-collection>")
|
||||
.query(Query::new_nearest(query_document));
|
||||
|
||||
let result = client.query(query_request).await.unwrap();
|
||||
println!("Result: {:?}", result);
|
||||
}
|
||||
```
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@
|
||||
import {QdrantClient} from "@qdrant/js-client-rest";
|
||||
|
||||
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>',
|
||||
});
|
||||
|
||||
@@ -11,7 +11,7 @@ const points = [
|
||||
id: 1,
|
||||
payload: { topic: "cooking", type: "dessert" },
|
||||
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>"
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ const result = await client.query(
|
||||
"<your-collection>",
|
||||
{
|
||||
query: {
|
||||
text: "What ingredients are needed for baking chocolate chip cookies?",
|
||||
text: "How to bake cookies?",
|
||||
model: "<the-model-to-use>"
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user