Convert all code snippets to testable snippets

This commit is contained in:
Abdon Pijpelink
2025-12-08 18:21:47 +01:00
parent 32492ca683
commit 7f2e456fad
20 changed files with 450 additions and 9 deletions
@@ -0,0 +1,41 @@
using Qdrant.Client;
using Qdrant.Client.Grpc;
public class Snippet
{
public static async Task Run()
{
var client = new QdrantClient(
host: "xyz-example.qdrant.io",
port: 6334,
https: true,
apiKey: "<your-api-key>"
);
await client.QueryAsync(
collectionName: "{collection_name}",
prefetch:
[
new()
{
Query = new Document()
{
Model = "openai/text-embedding-3-small",
Text = "How to bake cookies?",
Options = { ["openai-api-key"] = "<YOUR_OPENAI_API_KEY>", ["mrl"] = 64 },
},
Using = "small",
Limit = 1000,
},
],
query: new Document()
{
Model = "openai/text-embedding-3-small",
Text = "How to bake cookies?",
Options = { ["openai-api-key"] = "<YOUR_OPENAI_API_KEY>" },
},
usingVector: "large",
limit: 10
);
}
}
@@ -12,7 +12,7 @@ client, err := qdrant.NewClient(&qdrant.Config{
UseTLS: true,
})
client.Query(ctx, &qdrant.QueryPoints{
client.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "{collection_name}",
Prefetch: []*qdrant.PrefetchQuery{
{
@@ -42,4 +42,4 @@ client.Query(ctx, &qdrant.QueryPoints{
Using: qdrant.PtrOf("large"),
Limit: qdrant.PtrOf(uint64(10)),
})
```
```
@@ -0,0 +1,49 @@
package snippet
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
func Main() {
client, err := qdrant.NewClient(&qdrant.Config{
Host: "xyz-example.qdrant.io",
Port: 6334,
APIKey: "<paste-your-api-key-here>",
UseTLS: true,
})
if err != nil { panic(err) } // @hide
client.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "{collection_name}",
Prefetch: []*qdrant.PrefetchQuery{
{
Query: qdrant.NewQueryNearest(
qdrant.NewVectorInputDocument(&qdrant.Document{
Model: "openai/text-embedding-3-small",
Text: "How to bake cookies?",
Options: qdrant.NewValueMap(map[string]any{
"mrl": 64,
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
}),
}),
),
Using: qdrant.PtrOf("small"),
Limit: qdrant.PtrOf(uint64(1000)),
},
},
Query: qdrant.NewQueryNearest(
qdrant.NewVectorInputDocument(&qdrant.Document{
Model: "openai/text-embedding-3-small",
Text: "How to bake cookies?",
Options: qdrant.NewValueMap(map[string]any{
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
}),
}),
),
Using: qdrant.PtrOf("large"),
Limit: qdrant.PtrOf(uint64(10)),
})
}
@@ -0,0 +1,53 @@
package com.example.snippets_amalgamation;
import static io.qdrant.client.QueryFactory.nearest;
import static io.qdrant.client.ValueFactory.value;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Points;
import io.qdrant.client.grpc.Points.Document;
import io.qdrant.client.grpc.Points.PrefetchQuery;
import java.util.Map;
public class Snippet {
public static void run() throws Exception {
QdrantClient client =
new QdrantClient(
QdrantGrpcClient.newBuilder("xyz-example.qdrant.io", 6334, true)
.withApiKey("<your-api-key")
.build());
client
.queryAsync(
Points.QueryPoints.newBuilder()
.setCollectionName("{collection_name}")
.addPrefetch(
PrefetchQuery.newBuilder()
.setQuery(
nearest(
Document.newBuilder()
.setModel("openai/text-embedding-3-small")
.setText("How to bake cookies?")
.putAllOptions(
Map.of(
"openai-api-key",
value("<YOUR_OPENAI_API_KEY>"),
"mrl",
value(64)))
.build()))
.setUsing("small")
.setLimit(1000)
.build())
.setQuery(
nearest(
Document.newBuilder()
.setModel("openai/text-embedding-3-small")
.setText("How to bake cookies?")
.putAllOptions(Map.of("openai-api-key", value("<YOUR_OPENAI_API_KEY>")))
.build()))
.setUsing("large")
.build())
.get();
}
}
@@ -0,0 +1,30 @@
from qdrant_client import QdrantClient, models
client = QdrantClient(
url="https://xyz-example.qdrant.io:6333",
api_key="<your-api-key>",
cloud_inference=True
)
client.query_points(
collection_name="{collection_name}",
query=models.Document(
text="How to bake cookies?",
model="openai/text-embedding-3-small",
options={"openai-api-key": "<YOUR_OPENAI_API_KEY>"}
),
using="large",
limit=10,
prefetch=models.Prefetch(
query=models.Document(
text="How to bake cookies?",
model="openai/text-embedding-3-small",
options={
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
"mrl": 64
}
),
using="small",
limit=1000,
)
)
@@ -0,0 +1,45 @@
use std::collections::HashMap;
use qdrant_client::{
Qdrant, QdrantError,
qdrant::{Document, PrefetchQueryBuilder, Query, QueryPointsBuilder, Value},
};
pub async fn main() -> anyhow::Result<()> {
let client = Qdrant::from_url("http://localhost:6334").build()?;
client
.query(
QueryPointsBuilder::new("{collection_name}")
.add_prefetch(
PrefetchQueryBuilder::default()
.query(Query::new_nearest(Document {
text: "How to bake cookies?".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::<String, Value>::from_iter(vec![
(
"openai-api-key".to_string(),
Value::from("<YOUR_OPENAI_API_KEY>"),
),
("mrl".into(), Value::from(64)),
]),
}))
.using("small")
.limit(1000_u64),
)
.query(Query::new_nearest(Document {
text: "How to bake cookies?".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::from_iter(vec![(
"openai-api-key".into(),
"<YOUR_OPENAI_API_KEY>".into(),
)]),
}))
.using("large")
.limit(10_u64)
.build(),
)
.await?;
Ok(())
}
@@ -0,0 +1,41 @@
using Qdrant.Client;
using Qdrant.Client.Grpc;
public class Snippet
{
public static async Task Run()
{
var client = new QdrantClient(
host: "xyz-example.qdrant.io",
port: 6334,
https: true,
apiKey: "<your-api-key>"
);
await client.UpsertAsync(
collectionName: "{collection_name}",
points: new List<PointStruct>
{
new()
{
Id = 1,
Vectors = new Dictionary<string, Vector>
{
["large"] = new Document()
{
Model = "openai/text-embedding-3-small",
Text = "Recipe for baking chocolate chip cookies",
Options = { ["openai-api-key"] = "<YOUR_OPENAI_API_KEY>" },
},
["small"] = new Document()
{
Model = "openai/text-embedding-3-small",
Text = "Recipe for baking chocolate chip cookies",
Options = { ["openai-api-key"] = "<YOUR_OPENAI_API_KEY>", ["mrl"] = 64 },
},
},
},
}
);
}
}
@@ -12,7 +12,7 @@ client, err := qdrant.NewClient(&qdrant.Config{
UseTLS: true,
})
client.Upsert(ctx, &qdrant.UpsertPoints{
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "{collection_name}",
Points: []*qdrant.PointStruct{
{
@@ -16,13 +16,13 @@ client.upsert(
"large": models.Document(
text="Recipe for baking chocolate chip cookies",
model="openai/text-embedding-3-small",
options={"openai-api-key": "<YOUR_OPENAI_API_KEY"}
options={"openai-api-key": "<YOUR_OPENAI_API_KEY>"}
),
"small": models.Document(
text="Recipe for baking chocolate chip cookies",
model="openai/text-embedding-3-small",
options={
"openai-api-key": "<YOUR_OPENAI_API_KEY",
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
"mrl": 64
},
)
@@ -30,4 +30,4 @@ client.upsert(
)
],
)
```
```
@@ -0,0 +1,44 @@
package snippet
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
func Main() {
client, err := qdrant.NewClient(&qdrant.Config{
Host: "xyz-example.qdrant.io",
Port: 6334,
APIKey: "<paste-your-api-key-here>",
UseTLS: true,
})
if err != nil { panic(err) } // @hide
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "{collection_name}",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(uint64(1)),
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{
"large": qdrant.NewVectorDocument(&qdrant.Document{
Model: "openai/text-embedding-3-small",
Text: "Recipe for baking chocolate chip cookies",
Options: qdrant.NewValueMap(map[string]any{
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
}),
}),
"small": qdrant.NewVectorDocument(&qdrant.Document{
Model: "openai/text-embedding-3-small",
Text: "Recipe for baking chocolate chip cookies",
Options: qdrant.NewValueMap(map[string]any{
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
"mrl": 64,
}),
}),
}),
},
},
})
}
@@ -0,0 +1,56 @@
package com.example.snippets_amalgamation;
import static io.qdrant.client.PointIdFactory.id;
import static io.qdrant.client.ValueFactory.value;
import static io.qdrant.client.VectorFactory.vector;
import static io.qdrant.client.VectorsFactory.namedVectors;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Points.Document;
import io.qdrant.client.grpc.Points.PointStruct;
import java.util.List;
import java.util.Map;
public class Snippet {
public static void run() throws Exception {
QdrantClient client =
new QdrantClient(
QdrantGrpcClient.newBuilder("xyz-example.qdrant.io", 6334, true)
.withApiKey("<your-api-key")
.build());
client
.upsertAsync(
"{collection_name}",
List.of(
PointStruct.newBuilder()
.setId(id(1))
.setVectors(
namedVectors(
Map.of(
"large",
vector(
Document.newBuilder()
.setModel("openai/text-embedding-3-small")
.setText("Recipe for baking chocolate chip cookies")
.putAllOptions(
Map.of(
"openai-api-key", value("<YOUR_OPENAI_API_KEY>")))
.build()),
"small",
vector(
Document.newBuilder()
.setModel("openai/text-embedding-3-small")
.setText("Recipe for baking chocolate chip cookies")
.putAllOptions(
Map.of(
"openai-api-key",
value("<YOUR_OPENAI_API_KEY>"),
"mrl",
value(64)))
.build()))))
.build()))
.get();
}
}
@@ -0,0 +1,31 @@
from qdrant_client import QdrantClient, models
client = QdrantClient(
url="https://xyz-example.qdrant.io:6333",
api_key="<your-api-key>",
cloud_inference=True
)
client.upsert(
collection_name="{collection_name}",
points=[
models.PointStruct(
id=1,
vector={
"large": models.Document(
text="Recipe for baking chocolate chip cookies",
model="openai/text-embedding-3-small",
options={"openai-api-key": "<YOUR_OPENAI_API_KEY>"}
),
"small": models.Document(
text="Recipe for baking chocolate chip cookies",
model="openai/text-embedding-3-small",
options={
"openai-api-key": "<YOUR_OPENAI_API_KEY>",
"mrl": 64
},
)
},
)
],
)
@@ -0,0 +1,51 @@
use std::collections::HashMap;
use qdrant_client::{
Payload, Qdrant, QdrantError,
qdrant::{Document, NamedVectors, PointStruct, UpsertPointsBuilder, Value},
};
pub async fn main() -> anyhow::Result<()> {
let client = Qdrant::from_url("http://localhost:6334").build()?;
client
.upsert_points(
UpsertPointsBuilder::new(
"{collection_name}",
vec![PointStruct::new(
1,
NamedVectors::default()
.add_vector(
"large",
Document {
text: "Recipe for baking chocolate chip cookies".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::<String, Value>::from_iter(vec![(
"openai-api-key".into(),
"<YOUR_OPENAI_API_KEY>".into(),
)]),
},
)
.add_vector(
"small",
Document {
text: "Recipe for baking chocolate chip cookies".into(),
model: "openai/text-embedding-3-small".into(),
options: HashMap::<String, Value>::from_iter(vec![
(
"openai-api-key".into(),
Value::from("<YOUR_OPENAI_API_KEY>"),
),
("mrl".into(), Value::from(64)),
]),
},
),
Payload::default(),
)],
)
.wait(true),
)
.await?;
Ok(())
}