mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-06 19:38:30 +02:00
* Update Edge Rust snippets to the new request interfaces The edge crate replaced its mixed read interface with edge-owned request structs and fluent builders (qdrant/qdrant#9901). Update the Rust snippets under /documentation/edge accordingly: - retrieve() now takes a RetrieveRequest instead of a (&[ids], with_payload, with_vector) triple — this was a hard break. - Query and facet requests are built with QueryRequestBuilder / FacetRequestBuilder instead of struct literals, matching the published examples. Also note in the quickstart that parameters left unset on an EdgeConfig passed to load() now keep their persisted values, so the WAL-only config no longer resets the rest of the shard configuration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * Bump qdrant-edge to 0.8.0 in the rust snippet template 0.8.0 is the first release carrying the edge request structs and builders the snippets in the previous commit use. Lockfile refreshed with `cargo update -p qdrant-edge --precise 0.8.0`. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
69 lines
2.0 KiB
Rust
69 lines
2.0 KiB
Rust
// @block-start configure-bm25-shard
|
|
pub async fn main() -> anyhow::Result<()> {
|
|
const SHARD_DIRECTORY: &str = "./qdrant-edge-bm25";
|
|
fs_err::create_dir_all(SHARD_DIRECTORY)?; // @hide
|
|
|
|
use std::path::*;
|
|
use qdrant_edge::*;
|
|
|
|
let config = EdgeConfigBuilder::new()
|
|
.sparse_vector("text", EdgeSparseVectorParamsBuilder::new()
|
|
.modifier(Modifier::Idf)
|
|
.build())
|
|
.build();
|
|
|
|
let shard = EdgeShard::new(Path::new(SHARD_DIRECTORY), config)?;
|
|
// @block-end configure-bm25-shard
|
|
|
|
// @block-start create-bm25
|
|
use qdrant_edge::bm25_embed::*;
|
|
|
|
let bm25 = EdgeBm25::new(EdgeBm25Config {
|
|
language: Some("english".to_string()),
|
|
..Default::default()
|
|
})?;
|
|
// @block-end create-bm25
|
|
|
|
// @block-start embed-and-upsert
|
|
use qdrant_edge::external::serde_json::json;
|
|
use qdrant_edge::*;
|
|
|
|
let docs = [
|
|
(1u64, "the quick brown fox", "Article 1"),
|
|
(2, "a lazy dog sleeps", "Article 2"),
|
|
(3, "foxes are clever", "Article 3"),
|
|
];
|
|
|
|
let points = docs.iter().map(|(id, text, title)| {
|
|
PointStruct::new(
|
|
*id,
|
|
Vectors::new_named([("text", bm25.embed_document(text))]),
|
|
json!({ "title": title }),
|
|
).into()
|
|
}).collect();
|
|
|
|
shard.update(UpdateOperation::PointOperation(
|
|
PointOperations::UpsertPoints(PointInsertOperations::PointsList(points)),
|
|
))?;
|
|
shard.optimize()?;
|
|
// @block-end embed-and-upsert
|
|
|
|
// @block-start query-with-bm25
|
|
use qdrant_edge::*;
|
|
|
|
let query_vector = bm25.embed_query("clever fox");
|
|
|
|
let results = shard.query(
|
|
QueryRequestBuilder::new(3)
|
|
.query(ScoringQuery::Vector(QueryEnum::Nearest(NamedQuery {
|
|
query: VectorInternal::from(query_vector),
|
|
using: Some("text".to_string()),
|
|
})))
|
|
.with_payload(WithPayloadInterface::Bool(true))
|
|
.build(),
|
|
)?;
|
|
// @block-end query-with-bm25
|
|
|
|
Ok(())
|
|
}
|