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,28 @@
using Qdrant.Client;
using Qdrant.Client.Grpc;
public class Snippet
{
public static async Task Run()
{
var client = new QdrantClient("localhost", 6334); // @hide
await client.QueryAsync(
collectionName: "books",
query: new Document
{
Text = "Mieville",
Model = "qdrant/bm25",
Options =
{
["language"] = "none",
["tokenizer"] = "multilingual",
["ascii_folding"] = true,
},
},
usingVector: "author-bm25",
payloadSelector: true,
limit: 10
);
}
}
@@ -0,0 +1,22 @@
```csharp
using Qdrant.Client;
using Qdrant.Client.Grpc;
await client.QueryAsync(
collectionName: "books",
query: new Document
{
Text = "Mieville",
Model = "qdrant/bm25",
Options =
{
["language"] = "none",
["tokenizer"] = "multilingual",
["ascii_folding"] = true,
},
},
usingVector: "author-bm25",
payloadSelector: true,
limit: 10
);
```
@@ -0,0 +1,15 @@
```go
client.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "books",
Query: qdrant.NewQueryNearest(
qdrant.NewVectorInputDocument(&qdrant.Document{
Model: "qdrant/bm25",
Text: "Mieville",
Options: qdrant.NewValueMap(map[string]any{"language": "none", "tokenizer": "multilingual", "ascii_folding": true}),
}),
),
Using: qdrant.PtrOf("author-bm25"),
WithPayload: qdrant.NewWithPayload(true),
Limit: qdrant.PtrOf(uint64(10)),
})
```
@@ -0,0 +1,23 @@
```java
import static io.qdrant.client.QueryFactory.nearest;
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Points.*;
QdrantClient client =
client
.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("books")
.setQuery(
nearest(
Document.newBuilder().setText("Mieville").setModel("qdrant/bm25").build()))
.setUsing("author-bm25")
.setLimit(10)
.setWithPayload(enable(true))
.build())
.get();
```
@@ -0,0 +1,22 @@
```python
from qdrant_client import QdrantClient, models
client = QdrantClient(
url="https://xyz-example.qdrant.io:6333",
api_key="<your-api-key>",
cloud_inference=True,
)
# Note: these BM25 options are not supported by FastEmbed
client.query_points(
collection_name="books",
query=models.Document(
text="Mieville",
model="qdrant/bm25",
options={"language": "none", "tokenizer": "multilingual", "ascii_folding": True},
),
using="author-bm25",
limit=10,
with_payload=True,
)
```
@@ -0,0 +1,26 @@
```rust
use std::collections::HashMap;
use qdrant_client::Qdrant;
use qdrant_client::qdrant::{DocumentBuilder, Query, QueryPointsBuilder, Value};
let mut options = HashMap::new();
options.insert("language".to_string(), Value::from("none"));
options.insert("tokenizer".to_string(), Value::from("multilingual"));
options.insert("ascii_folding".to_string(), Value::from(true));
client
.query(
QueryPointsBuilder::new("books")
.query(Query::new_nearest(
DocumentBuilder::new("Mieville", "qdrant/bm25")
.options(options)
.build(),
))
.using("author-bm25")
.limit(10)
.with_payload(true)
.build(),
)
.await?;
```
@@ -0,0 +1,12 @@
```typescript
client.query("books", {
query: {
text: "Mieville",
model: "qdrant/bm25",
options: { language: "none", tokenizer: "multilingual", ascii_folding: true },
},
using: "author-bm25",
limit: 10,
with_payload: true,
});
```
@@ -0,0 +1,37 @@
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.Query(context.Background(), &qdrant.QueryPoints{
CollectionName: "books",
Query: qdrant.NewQueryNearest(
qdrant.NewVectorInputDocument(&qdrant.Document{
Model: "qdrant/bm25",
Text: "Mieville",
Options: qdrant.NewValueMap(map[string]any{"language": "none", "tokenizer": "multilingual", "ascii_folding": true}),
}),
),
Using: qdrant.PtrOf("author-bm25"),
WithPayload: qdrant.NewWithPayload(true),
Limit: qdrant.PtrOf(uint64(10)),
})
}
@@ -0,0 +1,28 @@
package com.example.snippets_amalgamation;
import static io.qdrant.client.QueryFactory.nearest;
import static io.qdrant.client.WithPayloadSelectorFactory.enable;
import io.qdrant.client.QdrantClient;
import io.qdrant.client.QdrantGrpcClient;
import io.qdrant.client.grpc.Points.*;
public class Snippet {
public static void run() throws Exception {
QdrantClient client =
new QdrantClient(QdrantGrpcClient.newBuilder("localhost", 6334, false).build()); // @hide
client
.queryAsync(
QueryPoints.newBuilder()
.setCollectionName("books")
.setQuery(
nearest(
Document.newBuilder().setText("Mieville").setModel("qdrant/bm25").build()))
.setUsing("author-bm25")
.setLimit(10)
.setWithPayload(enable(true))
.build())
.get();
}
}
@@ -0,0 +1,20 @@
from qdrant_client import QdrantClient, models
client = QdrantClient(
url="https://xyz-example.qdrant.io:6333",
api_key="<your-api-key>",
cloud_inference=True,
)
# Note: these BM25 options are not supported by FastEmbed
client.query_points(
collection_name="books",
query=models.Document(
text="Mieville",
model="qdrant/bm25",
options={"language": "none", "tokenizer": "multilingual", "ascii_folding": True},
),
using="author-bm25",
limit=10,
with_payload=True,
)
@@ -0,0 +1,30 @@
use std::collections::HashMap;
use qdrant_client::Qdrant;
use qdrant_client::qdrant::{DocumentBuilder, Query, QueryPointsBuilder, Value};
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("none"));
options.insert("tokenizer".to_string(), Value::from("multilingual"));
options.insert("ascii_folding".to_string(), Value::from(true));
client
.query(
QueryPointsBuilder::new("books")
.query(Query::new_nearest(
DocumentBuilder::new("Mieville", "qdrant/bm25")
.options(options)
.build(),
))
.using("author-bm25")
.limit(10)
.with_payload(true)
.build(),
)
.await?;
Ok(())
}
@@ -0,0 +1,14 @@
import { QdrantClient } from "@qdrant/js-client-rest"; // @hide
const client = new QdrantClient({ host: "localhost", port: 6333 }); // @hide
client.query("books", {
query: {
text: "Mieville",
model: "qdrant/bm25",
options: { language: "none", tokenizer: "multilingual", ascii_folding: true },
},
using: "author-bm25",
limit: 10,
with_payload: true,
});