Files
landing_page/qdrant-landing/content/documentation/headless/snippets/edge/bm25/python.py
T
Abdon PijpelinkandClaude Sonnet 4.6 ffe50340fa Edge 0.7 documentation updates (#2391)
* docs(edge): add "Modify the Vector Schema" step to quickstart

Documents the new Edge 0.7 API for adding and removing named vector
fields on an existing shard without recreating it, with Python and
Rust snippets.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(edge): mention quantization support in quickstart

Adds a note after the EdgeConfig snippet that Edge supports all four
quantization methods (Scalar, Product, Binary, TurboQuant), with a
link to the quantization guide.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(edge): add On-Device BM25 page for Edge 0.7

New guide covering the built-in BM25 sparse embedder: configuring a
sparse vector shard, creating a Bm25/EdgeBm25 embedder, embedding and
upserting documents, and querying. Includes Python and Rust snippets.
Also adds the page to the Edge index navigation table.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* docs(edge): add WAL segment size configuration to quickstart

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* Upgrade code snippets to Edge 0.7.2

* Review feedback

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-03 15:51:20 +02:00

49 lines
1.3 KiB
Python

from pathlib import Path
SHARD_DIRECTORY = "./qdrant-edge-bm25"
Path(SHARD_DIRECTORY).mkdir(parents=True, exist_ok=True) # @hide
# @block-start configure-bm25-shard
from qdrant_edge import (
EdgeConfig,
EdgeShard,
EdgeSparseVectorParams,
Modifier,
)
config = EdgeConfig(
sparse_vectors={"text": EdgeSparseVectorParams(modifier=Modifier.Idf)},
)
shard = EdgeShard.create(SHARD_DIRECTORY, config)
# @block-end configure-bm25-shard
# @block-start create-bm25
from qdrant_edge import Bm25, Bm25Config
bm25 = Bm25(Bm25Config(language="english"))
# @block-end create-bm25
# @block-start embed-and-upsert
from qdrant_edge import Point, UpdateOperation
shard.update(UpdateOperation.upsert_points([
Point(1, {"text": bm25.embed_document("the quick brown fox")}, {"title": "Article 1"}),
Point(2, {"text": bm25.embed_document("a lazy dog sleeps")}, {"title": "Article 2"}),
Point(3, {"text": bm25.embed_document("foxes are clever")}, {"title": "Article 3"}),
]))
shard.optimize()
# @block-end embed-and-upsert
# @block-start query-with-bm25
from qdrant_edge import Query, QueryRequest
query_vector = bm25.embed_query("clever fox")
results = shard.query(QueryRequest(
query=Query.Nearest(query_vector, using="text"),
limit=3,
with_payload=True,
))
# @block-end query-with-bm25