Add code snippets for the text search guide (#2056)

* Python snippets

* TS snippets

* Rust snippets

* Java snippets

* C# snippets

* Go snippets

* Generate .md files

* Hide client connection in Rust snippets

* Switch to builder pattern for Rust snippets

* Use Document::new instead of DocumentBuilder::new

* docs: Updated Go snippets

Signed-off-by: Anush008 <mail@anush.sh>

* docs: Updated Java snippets

Signed-off-by: Anush008 <anushshetty90@gmail.com>

* docs: Updated C# snippets

Signed-off-by: Anush008 <anushshetty90@gmail.com>

* docs: Updated BM25 avg_len Java snippet

Signed-off-by: Anush008 <anushshetty90@gmail.com>

* chore: review and format rust snippets

* chore: trigger pr update

* chore: remove qdrant_storage folder

* fix: remove tokio::main

* chore: trigger pr update

* Regenerate .md files

* George's feedback: set bm25 params at ingest-time, change Python client init to use cloud inference explicitly, and mark bm25 options unavailable in FastEmbed

---------

Signed-off-by: Anush008 <mail@anush.sh>
Signed-off-by: Anush008 <anushshetty90@gmail.com>
Co-authored-by: Anush008 <mail@anush.sh>
Co-authored-by: Anush008 <anushshetty90@gmail.com>
Co-authored-by: Daniel Boros <dancixx@gmail.com>
This commit is contained in:
Abdon Pijpelink
2026-01-16 17:57:08 +05:30
committed by GitHub
co-authored by Anush008 Anush008 Daniel Boros
parent b5e0908946
commit 2497c368ed
329 changed files with 7854 additions and 20 deletions
@@ -0,0 +1,36 @@
using Qdrant.Client;
using Qdrant.Client.Grpc;
public class Snippet
{
public static async Task Run()
{
var client = new QdrantClient("localhost", 6334); // @hide
await client.UpsertAsync(
collectionName: "books",
wait: true,
points: new List<PointStruct>
{
new()
{
Id = 1,
Vectors = new Dictionary<string, Vector>
{
["title-bm25"] = new Document
{
Text = "La Máquina del Tiempo",
Model = "qdrant/bm25",
},
},
Payload =
{
["title"] = "La Máquina del Tiempo",
["author"] = "H.G. Wells",
["isbn"] = "9788411486880",
},
},
}
);
}
}
@@ -0,0 +1,30 @@
```csharp
using Qdrant.Client;
using Qdrant.Client.Grpc;
await client.UpsertAsync(
collectionName: "books",
wait: true,
points: new List<PointStruct>
{
new()
{
Id = 1,
Vectors = new Dictionary<string, Vector>
{
["title-bm25"] = new Document
{
Text = "La Máquina del Tiempo",
Model = "qdrant/bm25",
},
},
Payload =
{
["title"] = "La Máquina del Tiempo",
["author"] = "H.G. Wells",
["isbn"] = "9788411486880",
},
},
}
);
```
@@ -0,0 +1,21 @@
```go
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "books",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(uint64(1)),
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{
"title-bm25": qdrant.NewVectorDocument(&qdrant.Document{
Model: "qdrant/bm25",
Text: "La Máquina del Tiempo",
}),
}),
Payload: qdrant.NewValueMap(map[string]any{
"title": "La Máquina del Tiempo",
"author": "H.G. Wells",
"isbn": "9788411486880",
}),
},
},
})
```
@@ -0,0 +1,34 @@
```java
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.*;
import java.util.*;
QdrantClient client =
PointStruct point =
PointStruct.newBuilder()
.setId(id(1))
.setVectors(
namedVectors(
Map.of(
"title-bm25",
vector(
Document.newBuilder()
.setText("La Máquina del Tiempo")
.setModel("qdrant/bm25")
.build()))))
.putAllPayload(
Map.of(
"title", value("La Máquina del Tiempo"),
"author", value("H.G. Wells"),
"isbn", value("9788411486880")))
.build();
client.upsertAsync("books", List.of(point)).get();
```
@@ -0,0 +1,30 @@
```python
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="books",
points=[
models.PointStruct(
id=1,
vector={
"title-bm25": models.Document(
text="La Máquina del Tiempo",
model="qdrant/bm25",
options={"language": "spanish"},
)
},
payload={
"title": "La Máquina del Tiempo",
"author": "H.G. Wells",
"isbn": "9788411486880",
},
)
],
)
```
@@ -0,0 +1,30 @@
```rust
use std::collections::HashMap;
use qdrant_client::qdrant::{DocumentBuilder, PointStruct, UpsertPointsBuilder, Value};
use qdrant_client::{Payload, Qdrant};
use serde_json::json;
let mut options = HashMap::new();
options.insert("language".to_string(), Value::from("spanish"));
let point = PointStruct::new(
1,
HashMap::from([(
"title-bm25".to_string(),
DocumentBuilder::new("La Máquina del Tiempo", "qdrant/bm25")
.options(options)
.build(),
)]),
Payload::try_from(json!({
"title": "La Máquina del Tiempo",
"author": "H.G. Wells",
"isbn": "9788411486880",
}))
.unwrap(),
);
client
.upsert_points(UpsertPointsBuilder::new("books", vec![point]).wait(true))
.await?;
```
@@ -0,0 +1,22 @@
```typescript
client.upsert("books", {
wait: true,
points: [
{
id: 1,
vector: {
"title-bm25": {
text: "La Máquina del Tiempo",
model: "qdrant/bm25",
options: { language: "spanish" },
},
},
payload: {
title: "La Máquina del Tiempo",
author: "H.G. Wells",
isbn: "9788411486880",
},
},
],
});
```
@@ -0,0 +1,43 @@
package snippet
// @hide-start
import (
"context"
"github.com/qdrant/go-client/qdrant"
)
// @hide-end
func Main() {
//@hide-start
client, err := qdrant.NewClient(&qdrant.Config{
Host: "localhost",
Port: 6334,
})
if err != nil {
panic(err)
}
// @hide-end
client.Upsert(context.Background(), &qdrant.UpsertPoints{
CollectionName: "books",
Points: []*qdrant.PointStruct{
{
Id: qdrant.NewIDNum(uint64(1)),
Vectors: qdrant.NewVectorsMap(map[string]*qdrant.Vector{
"title-bm25": qdrant.NewVectorDocument(&qdrant.Document{
Model: "qdrant/bm25",
Text: "La Máquina del Tiempo",
}),
}),
Payload: qdrant.NewValueMap(map[string]any{
"title": "La Máquina del Tiempo",
"author": "H.G. Wells",
"isbn": "9788411486880",
}),
},
},
})
}
@@ -0,0 +1,39 @@
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.*;
import java.util.*;
public class Snippet {
public static void run() throws Exception {
QdrantClient client =
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build()); // @hide
PointStruct point =
PointStruct.newBuilder()
.setId(id(1))
.setVectors(
namedVectors(
Map.of(
"title-bm25",
vector(
Document.newBuilder()
.setText("La Máquina del Tiempo")
.setModel("qdrant/bm25")
.build()))))
.putAllPayload(
Map.of(
"title", value("La Máquina del Tiempo"),
"author", value("H.G. Wells"),
"isbn", value("9788411486880")))
.build();
client.upsertAsync("books", List.of(point)).get();
}
}
@@ -0,0 +1,28 @@
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="books",
points=[
models.PointStruct(
id=1,
vector={
"title-bm25": models.Document(
text="La Máquina del Tiempo",
model="qdrant/bm25",
options={"language": "spanish"},
)
},
payload={
"title": "La Máquina del Tiempo",
"author": "H.G. Wells",
"isbn": "9788411486880",
},
)
],
)
@@ -0,0 +1,34 @@
use std::collections::HashMap;
use qdrant_client::qdrant::{DocumentBuilder, PointStruct, UpsertPointsBuilder, Value};
use qdrant_client::{Payload, Qdrant};
use serde_json::json;
pub async fn main() -> anyhow::Result<()> {
let client = Qdrant::from_url("http://localhost:6334").build()?; // @hide
let mut options = HashMap::new();
options.insert("language".to_string(), Value::from("spanish"));
let point = PointStruct::new(
1,
HashMap::from([(
"title-bm25".to_string(),
DocumentBuilder::new("La Máquina del Tiempo", "qdrant/bm25")
.options(options)
.build(),
)]),
Payload::try_from(json!({
"title": "La Máquina del Tiempo",
"author": "H.G. Wells",
"isbn": "9788411486880",
}))
.unwrap(),
);
client
.upsert_points(UpsertPointsBuilder::new("books", vec![point]).wait(true))
.await?;
Ok(())
}
@@ -0,0 +1,24 @@
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
client.upsert("books", {
wait: true,
points: [
{
id: 1,
vector: {
"title-bm25": {
text: "La Máquina del Tiempo",
model: "qdrant/bm25",
options: { language: "spanish" },
},
},
payload: {
title: "La Máquina del Tiempo",
author: "H.G. Wells",
isbn: "9788411486880",
},
},
],
});