Files
qdrant/lib/edge/python/examples/load-existing.py
qdrant-cloud-bot 09b3ff00cb refactor(edge): split EdgeShard load into new() and load() (#8326)
* 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>
2026-03-18 15:25:01 +01:00

71 lines
1.9 KiB
Python
Executable File

#!/usr/bin/env python3
# See lib/edge/publish/examples/src/bin/load-existing.rs for the equivalent Rust example.
from common import *
from qdrant_edge import *
# Create *new* edge shard and upsert some points
edge = load_new_shard()
edge.update(
UpdateOperation.upsert_points(
[
Point(
1,
[6.0, 9.0, 4.0, 2.0],
{
"null": None,
"str": "string",
"uint": 42,
"int": -69,
"float": 4.20,
"bool": True,
"obj": {
"null": None,
"str": "string",
"uint": 42,
"int": -69,
"float": 4.20,
"bool": True,
"obj": {},
"arr": [],
},
"arr": [None, "string", 42, -69, 4.20, True, {}, []],
},
),
Point(
"e9408f2b-b917-4af1-ab75-d97ac6b2c047",
[6.0, 9.0, 3.0, -2.0],
{
"hello": "world",
"price": 199.99,
},
),
Point(
uuid.uuid4(),
[1.0, 6.0, 4.0, 2.0],
{
"hello": "world",
"price": 999.99,
},
),
]
)
)
expected_points = edge.scroll(
ScrollRequest(limit=5, with_vector=True, with_payload=True)
)
print(expected_points)
# Re-load edge shard from disk (load existing)
edge.close()
edge = EdgeShard.load(TMP_DIR)
points = edge.scroll(ScrollRequest(limit=5, with_vector=True, with_payload=True))
print(points)
# TODO: Implement `__eq__` for edge types 🌚
# assert points == expected_points