mirror of
https://github.com/qdrant/qdrant.git
synced 2026-07-26 12:41:04 -05:00
* refactor(edge): split EdgeShard load into new() and load() - new(path, config): create edge shard only when path has no existing segments - load(path, config?): load from existing files; config optional (load from edge_config.json or infer from segments) - Helpers: has_existing_segments, ensure_dirs_and_open_wal, resolve_initial_config, load_segments, ensure_appendable_segment - Python: EdgeShard.create_new(path, config); __init__ still calls load() - Examples use new() for creation and load(path, None) for reopen - Error instead of panic on config mismatch; explicit load/create in Python - fix: use OptimizerThresholds.deferred_internal_id for dev compatibility Made-with: Cursor * rollback threshold changes * fix(edge): address dancixx review comments - Persist inferred config in load() when edge_config.json does not exist (SaveOnDisk::new only saves when file exists) - Python: add #[new] delegating to load() for backward compatibility - qdrant_edge.pyi: Optional return types for deleted_threshold, vacuum_min_vector_number, default_segment_number; add __init__ doc Made-with: Cursor * Revert "fix(edge): address dancixx review comments" This reverts commit 370e21a6c74c41210e1658f89814395cb86ed81c. * fix: optional returns * fix: save config it is not exist * fix: save data on disk always * fix: python examples * chore: remove edge.close() * fix: wal lock * fix: rename of EdgeShardConfig -> EdgeConfig --------- Co-authored-by: Cursor Agent <agent@cursor.com> Co-authored-by: Andrey Vasnetsov <andrey@vasnetsov.com> Co-authored-by: Daniel Boros <dancixx@gmail.com>
92 lines
2.6 KiB
Python
92 lines
2.6 KiB
Python
# Common helper items for the examples.
|
|
# See lib/edge/publish/examples/src/lib.rs for the equivalent Rust helpers.
|
|
|
|
import os
|
|
import shutil
|
|
import uuid
|
|
from pathlib import Path
|
|
|
|
from qdrant_edge import (
|
|
Distance,
|
|
EdgeConfig,
|
|
EdgeShard,
|
|
EdgeVectorParams,
|
|
Point,
|
|
UpdateOperation,
|
|
)
|
|
|
|
DATA_DIR = Path(__file__).parent.parent.parent / "data"
|
|
TMP_DIR = DATA_DIR / "tmp"
|
|
|
|
|
|
def load_new_shard():
|
|
"""Create a new edge shard (clears DATA_DIRECTORY first)."""
|
|
print("---- Load shard ----")
|
|
|
|
# Clear and recreate tmp directory
|
|
if os.path.exists(TMP_DIR):
|
|
shutil.rmtree(TMP_DIR)
|
|
|
|
os.makedirs(TMP_DIR)
|
|
|
|
config = EdgeConfig(
|
|
vectors=EdgeVectorParams(size=4, distance=Distance.Dot),
|
|
)
|
|
|
|
return EdgeShard.create(TMP_DIR, config)
|
|
|
|
|
|
def fill_dummy_data(shard: EdgeShard):
|
|
shard.update(
|
|
UpdateOperation.upsert_points(
|
|
[
|
|
Point(
|
|
1,
|
|
[0.05, 0.61, 0.76, 0.74],
|
|
{"color": "red", "city": ["Moscow", "Berlin"]},
|
|
),
|
|
Point(2, [0.19, 0.81, 0.75, 0.11], {"color": "red", "city": "Mexico"}),
|
|
Point(
|
|
3,
|
|
[0.36, 0.55, 0.47, 0.94],
|
|
{"color": "blue", "city": ["Berlin", "Barcelona"]},
|
|
),
|
|
Point(
|
|
4,
|
|
[0.12, 0.34, 0.56, 0.78],
|
|
{"color": "green", "city": "Lisbon", "rating": 4.5},
|
|
),
|
|
Point(
|
|
5,
|
|
[0.88, 0.12, 0.33, 0.44],
|
|
{"color": "yellow", "city": ["Paris"], "active": True},
|
|
),
|
|
Point(
|
|
6,
|
|
[0.21, 0.22, 0.23, 0.24],
|
|
{"color": "blue", "city": "Tokyo", "tags": ["night", "food"]},
|
|
),
|
|
Point(
|
|
7,
|
|
[0.99, 0.01, 0.50, 0.50],
|
|
{"color": "red", "city": ["New York", "Boston"], "visits": 7},
|
|
),
|
|
Point(
|
|
8,
|
|
[0.10, 0.20, 0.30, 0.40],
|
|
{"color": "blue", "city": "Seoul", "meta": {"source": "import"}},
|
|
),
|
|
Point(
|
|
9,
|
|
[0.45, 0.55, 0.65, 0.75],
|
|
{"color": "green", "city": ["Berlin"], "score": 0.92},
|
|
),
|
|
Point(
|
|
10,
|
|
[0.01, 0.02, 0.03, 0.04],
|
|
{"color": "yellow", "city": None, "featured": False},
|
|
),
|
|
]
|
|
)
|
|
)
|