mirror of
https://github.com/qdrant/landing_page.git
synced 2026-10-03 01:48:32 +02:00
* 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>
191 lines
5.8 KiB
Rust
191 lines
5.8 KiB
Rust
use std::path::Path;
|
|
|
|
use qdrant_edge::EdgeShard;
|
|
use qdrant_edge::{
|
|
Condition, CreateIndex, CreateVectorName, Distance, EdgeConfigBuilder,
|
|
EdgeOptimizersConfig, EdgeVectorParamsBuilder, FacetRequest, FieldCondition,
|
|
FieldIndexOperations, Filter, Match, MatchValue, Modifier, NamedQuery,
|
|
PayloadFieldSchema, PayloadSchemaType, PointId, PointInsertOperations,
|
|
PointOperations, PointStruct, PointStructPersisted, QueryEnum, QueryRequest,
|
|
ScoringQuery, SparseVectorConfig, UpdateOperation, ValueVariants,
|
|
VectorNameConfig, VectorNameOperations, Vectors, WalOptions,
|
|
WithPayloadInterface, WithVector,
|
|
};
|
|
use serde_json::json;
|
|
|
|
pub async fn main() -> anyhow::Result<()> {
|
|
// @block-start create-storage-directory
|
|
const SHARD_DIRECTORY: &str = "./qdrant-edge-directory";
|
|
|
|
fs_err::create_dir_all(SHARD_DIRECTORY)?;
|
|
// @block-end create-storage-directory
|
|
|
|
// @block-start configure-edge-shard
|
|
const VECTOR_NAME: &str = "my-vector";
|
|
const VECTOR_DIMENSION: usize = 4;
|
|
|
|
let config = EdgeConfigBuilder::new()
|
|
.on_disk_payload(true)
|
|
.vector(
|
|
VECTOR_NAME,
|
|
EdgeVectorParamsBuilder::new(VECTOR_DIMENSION, Distance::Cosine)
|
|
.on_disk(true)
|
|
.build(),
|
|
)
|
|
.build();
|
|
// @block-end configure-edge-shard
|
|
|
|
// @block-start initialize-edge-shard
|
|
let edge_shard = EdgeShard::new(
|
|
Path::new(SHARD_DIRECTORY),
|
|
config,
|
|
)?;
|
|
// @block-end initialize-edge-shard
|
|
|
|
// @block-start upsert-points
|
|
let points: Vec<PointStructPersisted> = vec![
|
|
PointStruct::new(
|
|
1u64,
|
|
Vectors::new_named([(VECTOR_NAME, vec![0.1f32, 0.2, 0.3, 0.4])]),
|
|
json!({"color": "red"}),
|
|
)
|
|
.into(),
|
|
];
|
|
|
|
edge_shard.update(UpdateOperation::PointOperation(
|
|
PointOperations::UpsertPoints(
|
|
PointInsertOperations::PointsList(points),
|
|
),
|
|
))?;
|
|
// @block-end upsert-points
|
|
|
|
// @block-start retrieve-point
|
|
let retrieved = edge_shard.retrieve(
|
|
&[PointId::NumId(1)],
|
|
Some(WithPayloadInterface::Bool(true)),
|
|
Some(WithVector::Bool(false)),
|
|
)?;
|
|
// @block-end retrieve-point
|
|
|
|
// @block-start modify-vector-schema
|
|
edge_shard.update(UpdateOperation::VectorNameOperation(
|
|
VectorNameOperations::CreateVectorName(CreateVectorName {
|
|
vector_name: "text".to_string(),
|
|
config: VectorNameConfig::sparse(SparseVectorConfig {
|
|
modifier: Some(Modifier::Idf),
|
|
datatype: None,
|
|
}),
|
|
}),
|
|
))?;
|
|
// @block-end modify-vector-schema
|
|
|
|
// @block-start query-points
|
|
let results = edge_shard.query(QueryRequest {
|
|
prefetches: vec![],
|
|
query: Some(ScoringQuery::Vector(QueryEnum::Nearest(NamedQuery {
|
|
query: vec![0.2f32, 0.1, 0.9, 0.7].into(),
|
|
using: Some(VECTOR_NAME.to_string()),
|
|
}))),
|
|
filter: None,
|
|
score_threshold: None,
|
|
limit: 10,
|
|
offset: 0,
|
|
params: None,
|
|
with_vector: WithVector::Bool(false),
|
|
with_payload: WithPayloadInterface::Bool(true),
|
|
})?;
|
|
// @block-end query-points
|
|
|
|
// @block-start filter
|
|
let filter = Filter {
|
|
should: None,
|
|
min_should: None,
|
|
must: Some(vec![Condition::Field(FieldCondition::new_match(
|
|
"color".try_into().unwrap(),
|
|
Match::Value(MatchValue {
|
|
value: ValueVariants::String("red".to_string()),
|
|
}),
|
|
))]),
|
|
must_not: None,
|
|
};
|
|
|
|
let results = edge_shard.query(QueryRequest {
|
|
prefetches: vec![],
|
|
query: Some(ScoringQuery::Vector(QueryEnum::Nearest(NamedQuery {
|
|
query: vec![0.2f32, 0.1, 0.9, 0.7].into(),
|
|
using: Some(VECTOR_NAME.to_string()),
|
|
}))),
|
|
filter: Some(filter),
|
|
score_threshold: None,
|
|
limit: 10,
|
|
offset: 0,
|
|
params: None,
|
|
with_vector: WithVector::Bool(false),
|
|
with_payload: WithPayloadInterface::Bool(true),
|
|
})?;
|
|
// @block-end filter
|
|
|
|
// @block-start facet
|
|
let facet_response = edge_shard.facet(FacetRequest {
|
|
key: "color".try_into().unwrap(),
|
|
limit: 10,
|
|
filter: None,
|
|
exact: false,
|
|
})?;
|
|
// @block-end facet
|
|
|
|
// @block-start optimize
|
|
edge_shard.optimize()?;
|
|
// @block-end optimize
|
|
|
|
// @block-start configure-optimizer
|
|
let config = EdgeConfigBuilder::new()
|
|
.on_disk_payload(true)
|
|
.vector(
|
|
VECTOR_NAME,
|
|
EdgeVectorParamsBuilder::new(VECTOR_DIMENSION, Distance::Cosine)
|
|
.on_disk(true)
|
|
.build(),
|
|
)
|
|
.optimizers(EdgeOptimizersConfig {
|
|
deleted_threshold: Some(0.2),
|
|
vacuum_min_vector_number: Some(100),
|
|
default_segment_number: Some(2),
|
|
..Default::default()
|
|
})
|
|
.build();
|
|
// @block-end configure-optimizer
|
|
|
|
// @block-start create-payload-index
|
|
edge_shard.update(UpdateOperation::FieldIndexOperation(
|
|
FieldIndexOperations::CreateIndex(CreateIndex {
|
|
field_name: "color".try_into().unwrap(),
|
|
field_schema: Some(PayloadFieldSchema::FieldType(
|
|
PayloadSchemaType::Keyword,
|
|
)),
|
|
}),
|
|
))?;
|
|
// @block-end create-payload-index
|
|
|
|
// @block-start close-edge-shard
|
|
drop(edge_shard);
|
|
// @block-end close-edge-shard
|
|
|
|
// @block-start load-edge-shard
|
|
let edge_shard = EdgeShard::load(Path::new(SHARD_DIRECTORY), None)?;
|
|
// @block-end load-edge-shard
|
|
|
|
// @block-start wal-options
|
|
let config = EdgeConfigBuilder::new()
|
|
.wal_options(WalOptions {
|
|
segment_capacity: 4 * 1024 * 1024,
|
|
..Default::default()
|
|
})
|
|
.build();
|
|
|
|
let edge_shard = EdgeShard::load(Path::new(SHARD_DIRECTORY), Some(config))?;
|
|
// @block-end wal-options
|
|
|
|
Ok(())
|
|
}
|