Skip to content

feat: add Redis Vector Set support - #356

Open
happy-v587 wants to merge 33 commits into
arana-db:mainfrom
happy-v587:feat/redis-vector
Open

feat: add Redis Vector Set support#356
happy-v587 wants to merge 33 commits into
arana-db:mainfrom
happy-v587:feat/redis-vector

Conversation

@happy-v587

@happy-v587 happy-v587 commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

变更说明

基于 Discussion #331 为 Kiwi 增加 Redis Vector Set 的 standalone Phase 1 实现。

本次实现包括:

  • 新增 VectorSet 数据类型和独立的 vector_data_cf,持久化 FP32 向量及其元数据。
  • 新增 VADDVSIMVREMVCARDVDIMVEMBVISMEMBER 七个命令。
  • 使用 cosine 相似度和 FLAT 全量扫描执行精确 Top-K 查询。
  • 按 user key 将 Vector Set 的元数据和成员路由到同一个 RocksDB instance,并接入删除、过期及 compaction 清理流程。
  • 补充 RESP2/RESP3 下 Double、Map 和 Null 的兼容编码。
  • 增加 storage 单元测试与真实服务 Python 集成测试。

实现边界

  • 当前仅支持 standalone;集群模式会返回明确的 unsupported 错误。
  • 当前仅支持 FP32、NOQUANT 和 cosine;尚未实现 Q8、BIN、HNSW/IVF、VINFOINFO VECTORVEMB RAW
  • VSIMVSIM ... TRUTH 当前均使用同一套精确 FLAT 搜索。

用户影响

用户可以在 standalone Kiwi 上持久化、查询、删除 Vector Set 成员,并通过 Redis RESP2 或 RESP3 客户端执行精确相似度搜索。

验证

  • make fmt
  • make lint
  • make build
  • make test
  • KIWI_PORT=7389 pytest -q tests/python/test_vector_set_commands.py(14 passed)

Summary by CodeRabbit

  • New Features

    • Added vector set support with VADD, VREM, VCARD, VDIM, VEMB, VISMEMBER, and VSIM.
    • Supports FP32 vectors, cosine similarity, top-K search, element-based queries, scores, and deterministic result ordering.
    • Added vector-set expiration, deletion, recreation, binary-safe members, and atomic updates.
    • Added RESP2 and RESP3 response compatibility, including WITHSCORES.
  • Bug Fixes

    • Improved handling of invalid vectors, dimension mismatches, missing keys, wrong types, and unsupported options.
    • Added follower redirection for vector write commands.
  • Tests

    • Added comprehensive Rust and Python coverage for vector commands, storage lifecycle, expiration, routing, and protocol behavior.

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds standalone Redis Vector Set support across storage, command parsing, RESP2/RESP3 encoding, lifecycle handling, cluster routing, and Rust/Python tests. It introduces vector codecs, atomic mutations, point reads, FLAT similarity search, seven commands, and a Phase 1 implementation plan.

Changes

Redis Vector Set

Layer / File(s) Summary
Vector contracts and codecs
src/storage/src/format_base_value.rs, src/storage/src/format_vector.rs, src/storage/src/vector.rs
Adds the VectorSet datatype, canonical FP32 vectors, persisted metadata/value codecs, cosine scoring, query types, and deterministic top-K search.
Column-family persistence and lifecycle
src/storage/src/redis.rs, src/storage/src/redis_strings.rs, src/storage/src/*compaction_filter.rs, src/raft/src/lib.rs, src/conf/src/raft_type.rs
Adds VectorDataCF across RocksDB, batch, binlog, compaction, expiration, deletion, scanning, and flush paths.
Vector storage operations and routing
src/storage/src/redis_vectors.rs, src/storage/src/storage_impl.rs, src/storage/src/lib.rs
Implements atomic vadd/vrem, point reads, vsim, snapshots, generation handling, and slot-based storage routing.
Command execution and RESP negotiation
src/cmd/src/vector/*, src/cmd/src/table.rs, src/resp/src/encode.rs, src/net/tests/*
Adds parsing and handlers for seven vector commands, command registration, RESP2 downgrading, and follower redirection coverage.
End-to-end verification and implementation plan
src/storage/tests/redis_vector_test.rs, tests/python/test_vector_set_commands.py, src/resp/tests/*, docs/superpowers/plans/*
Adds storage, protocol, lifecycle, routing, cluster, malformed-input, and Python client tests, plus the Phase 1 implementation plan.

Estimated code review effort: 5 (Critical) | ~120 minutes

Possibly related PRs

  • arana-db/kiwi#183: Provides the compaction-filter framework extended here for VectorSet.
  • arana-db/kiwi#231: Introduces batch abstractions extended here for VectorDataCF.
  • arana-db/kiwi#291: Provides leader-gating plumbing exercised by vector write redirection tests.

Suggested labels: ✏️ Feature

Suggested reviewers: alexstocks

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the feature, but it does not follow the required template sections or include the issue link, type, checklist, or testing headings. Rewrite it to match the template with Description, Type of Change, Checklist, Testing, and Additional Context sections, plus the issue reference.
Docstring Coverage ⚠️ Warning Docstring coverage is 56.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: adding Redis Vector Set support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@happy-v587
happy-v587 marked this pull request as ready for review July 20, 2026 04:12
@happy-v587
happy-v587 requested a review from AlexStocks July 20, 2026 04:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/resp/src/encode.rs (1)

232-281: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Reduce duplication: delegate to existing append_* helpers.

These arms re-implement append_null, append_boolean, append_double, append_big_number, append_bulk_error, and append_verbatim_string byte-for-byte. Two copies of the same wire formatting (notably the Double NaN/inf handling and the VerbatimString length logic) can silently diverge on future edits. Consider calling the helpers directly.

♻️ Example delegation
-            RespData::Null => {
-                self.buffer.extend_from_slice(b"_");
-                self.append_crlf()
-            }
-            RespData::Boolean(value) => {
-                self.buffer.extend_from_slice(b"#");
-                self.buffer
-                    .extend_from_slice(if *value { b"t" } else { b"f" });
-                self.append_crlf()
-            }
-            RespData::Double(value) => {
-                if value.is_nan() {
-                    self.buffer.extend_from_slice(b",nan");
-                } else if value.is_infinite() {
-                    self.buffer.extend_from_slice(if value.is_sign_negative() {
-                        b",-inf"
-                    } else {
-                        b",inf"
-                    });
-                } else {
-                    let _ = write!(self.buffer, ",{value}");
-                }
-                self.append_crlf()
-            }
+            RespData::Null => self.append_null(),
+            RespData::Boolean(value) => self.append_boolean(*value),
+            RespData::Double(value) => self.append_double(*value),
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/resp/src/encode.rs` around lines 232 - 281, Update the RespData encoding
match arms for Null, Boolean, Double, BigNumber, BulkError, and VerbatimString
to delegate directly to their existing append_null, append_boolean,
append_double, append_big_number, append_bulk_error, and append_verbatim_string
helpers. Remove the duplicated byte-formatting and validation logic while
preserving each helper’s current output.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/storage/src/meta_compaction_filter.rs`:
- Around line 364-381: Add #[allow(clippy::unwrap_used)] to the
test_vectorset_meta_value_expired function so its existing encoded_key unwrap is
explicitly permitted under the project’s Clippy settings.

In `@src/storage/tests/redis_vector_test.rs`:
- Around line 378-384: Replace direct tempfile::tempdir() usage in
test_storage_routes_all_members_of_one_vectorset_to_one_instance,
test_expired_vectorset_reads_as_missing, and
test_vector_storage_rejects_cluster_mode with unique_test_db_path(); call
safe_cleanup_test_db(&path) before opening storage, pass &path to open(), and
call safe_cleanup_test_db(&path) at each test’s end. Apply these changes at
src/storage/tests/redis_vector_test.rs:378-384, 446-452, and 506-512.

---

Nitpick comments:
In `@src/resp/src/encode.rs`:
- Around line 232-281: Update the RespData encoding match arms for Null,
Boolean, Double, BigNumber, BulkError, and VerbatimString to delegate directly
to their existing append_null, append_boolean, append_double, append_big_number,
append_bulk_error, and append_verbatim_string helpers. Remove the duplicated
byte-formatting and validation logic while preserving each helper’s current
output.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4b9c8226-57d2-4f25-8bf0-c96a5a0392c3

📥 Commits

Reviewing files that changed from the base of the PR and between cdada8b and 380cde9.

📒 Files selected for processing (25)
  • docs/superpowers/plans/2026-07-19-redis-vector-set.md
  • src/cmd/src/lib.rs
  • src/cmd/src/table.rs
  • src/cmd/src/vector.rs
  • src/conf/src/raft_type.rs
  • src/raft/src/lib.rs
  • src/resp/src/encode.rs
  • src/resp/src/negotiation.rs
  • src/resp/tests/integration_tests.rs
  • src/storage/src/batch.rs
  • src/storage/src/data_compaction_filter.rs
  • src/storage/src/format_base_value.rs
  • src/storage/src/format_vector.rs
  • src/storage/src/lib.rs
  • src/storage/src/logindex/types.rs
  • src/storage/src/meta_compaction_filter.rs
  • src/storage/src/redis.rs
  • src/storage/src/redis_strings.rs
  • src/storage/src/redis_vectors.rs
  • src/storage/src/storage.rs
  • src/storage/src/storage_impl.rs
  • src/storage/src/vector.rs
  • src/storage/tests/redis_basic_test.rs
  • src/storage/tests/redis_vector_test.rs
  • tests/python/test_vector_set_commands.py

Comment thread src/storage/src/meta_compaction_filter.rs
Comment thread src/storage/tests/redis_vector_test.rs

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/superpowers/plans/2026-07-19-redis-vector-set.md`:
- Line 423: The VectorSet recreation flow must guarantee collision-free
generations instead of relying solely on timestamps. Update the VectorMeta
generation logic around VectorMeta::new so each expired-and-recreated VectorSet
receives a monotonic or otherwise unique version, and ensure stale VectorDataCF
rows cannot be addressed by the new generation; alternatively, add a rapid
expire/recreate test that proves timestamp-based generations cannot collide.
- Line 467: Update the documented test command to avoid passing two explicit
filters to cargo test. Run the vector and format_vector test filters as separate
commands, or replace them with one broader valid filter while preserving
coverage of both test groups.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: edc0f854-de79-48e2-af78-de6e26e6b763

📥 Commits

Reviewing files that changed from the base of the PR and between cb68d38 and 049f9c0.

📒 Files selected for processing (25)
  • docs/superpowers/plans/2026-07-19-redis-vector-set.md
  • src/cmd/src/lib.rs
  • src/cmd/src/table.rs
  • src/cmd/src/vector.rs
  • src/conf/src/raft_type.rs
  • src/raft/src/lib.rs
  • src/resp/src/encode.rs
  • src/resp/src/negotiation.rs
  • src/resp/tests/integration_tests.rs
  • src/storage/src/batch.rs
  • src/storage/src/data_compaction_filter.rs
  • src/storage/src/format_base_value.rs
  • src/storage/src/format_vector.rs
  • src/storage/src/lib.rs
  • src/storage/src/logindex/types.rs
  • src/storage/src/meta_compaction_filter.rs
  • src/storage/src/redis.rs
  • src/storage/src/redis_strings.rs
  • src/storage/src/redis_vectors.rs
  • src/storage/src/storage.rs
  • src/storage/src/storage_impl.rs
  • src/storage/src/vector.rs
  • src/storage/tests/redis_basic_test.rs
  • src/storage/tests/redis_vector_test.rs
  • tests/python/test_vector_set_commands.py
🚧 Files skipped from review as they are similar to previous changes (23)
  • src/cmd/src/lib.rs
  • src/conf/src/raft_type.rs
  • src/cmd/src/table.rs
  • src/storage/src/storage.rs
  • src/storage/src/meta_compaction_filter.rs
  • src/raft/src/lib.rs
  • src/storage/src/batch.rs
  • src/storage/src/logindex/types.rs
  • src/storage/src/format_base_value.rs
  • src/storage/src/lib.rs
  • src/resp/src/negotiation.rs
  • src/storage/src/redis_strings.rs
  • src/storage/src/data_compaction_filter.rs
  • src/storage/tests/redis_basic_test.rs
  • tests/python/test_vector_set_commands.py
  • src/cmd/src/vector.rs
  • src/storage/src/redis.rs
  • src/storage/src/storage_impl.rs
  • src/resp/src/encode.rs
  • src/storage/src/format_vector.rs
  • src/storage/src/vector.rs
  • src/storage/src/redis_vectors.rs
  • src/storage/tests/redis_vector_test.rs

Comment thread docs/superpowers/plans/2026-07-19-redis-vector-set.md Outdated
Comment thread docs/superpowers/plans/2026-07-19-redis-vector-set.md Outdated
happy-v587 and others added 3 commits July 25, 2026 23:49
…ions

- Remove MODULE_NO_CLUSTER guard so vector commands work in Raft Group
  clusters (binlog replication); keep follower redirect for writes.
- Split src/cmd/src/vector.rs into one module per command.
- Introduce SimilarityMetric (currently Cosine) persisted in VectorMeta.
- Introduce VectorSearchEngine (currently Flat) for future HNSW.
- Add RocksDB encoding layout comments for vector meta/data values.
- Update the Redis Vector Set superpower plan to reflect cluster support.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/storage/src/vector.rs (1)

182-204: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Non-obvious inverted Ord — consider a clarifying comment.

Ord::cmp reverses score comparison (other.score.total_cmp(&self.score)) to make BinaryHeap::peek() surface the worst candidate, but the tie-break (self.element.cmp(&other.element)) is not reversed. This is correct (verified against flat_search's eviction logic and the final sort_by at lines 257-262, which are consistent), but the asymmetry is easy to break during future edits. A short comment explaining "reversed for min-heap-of-top-k semantics" would help future maintainers avoid introducing a sign-flip bug.

📝 Suggested comment
 impl Ord for ScoredCandidate {
+    // Reversed on `score` so `BinaryHeap` (a max-heap) surfaces the *worst*
+    // candidate via `peek()`, enabling top-`count` retention via eviction.
+    // The element tie-break is intentionally NOT reversed.
     fn cmp(&self, other: &Self) -> Ordering {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage/src/vector.rs` around lines 182 - 204, Add a concise explanatory
comment in ScoredCandidate::cmp documenting that the score ordering is
intentionally reversed so BinaryHeap::peek() exposes the worst top-k candidate,
while the element tie-break remains in its existing direction. Do not alter the
comparison behavior.
src/storage/src/format_vector.rs (1)

134-201: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Missing regression test for unsupported-metric rejection.

SimilarityMetric::from_u8 (Line 179) is new validation logic replacing the old hardcoded cosine check, but vector_codecs_reject_malformed_bytes only mutates the format byte (offset 17), not the metric byte (offset 19). Add a case that sets an unsupported metric byte and asserts VectorMeta::decode errors, to directly cover the new from_u8 rejection path.

✅ Suggested additional test case
         let mut bad_meta_format = encoded_meta;
         bad_meta_format[17] = 0;
         assert!(VectorMeta::decode(&bad_meta_format).is_err());
+
+        let mut bad_metric = bad_meta_format;
+        bad_metric[17] = VECTOR_META_FORMAT;
+        bad_metric[19] = 0xFF;
+        assert!(VectorMeta::decode(&bad_metric).is_err());
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage/src/format_vector.rs` around lines 134 - 201, Add a regression
case to the vector metadata malformed-bytes test,
`vector_codecs_reject_malformed_bytes`, that mutates the metric byte at offset
19 to an unsupported value and asserts `VectorMeta::decode` returns an error.
Keep the existing format-byte case and target the `SimilarityMetric::from_u8`
validation path.
src/storage/tests/redis_vector_test.rs (1)

458-467: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Decode VectorMeta before mutating its stale TTL fields.

The current test slices VectorMeta bytes with hard-coded index math, even though VectorMeta::encode/decode define the field layout. Decode the CF value, mutate only version/is_deleted-related TTL logic via accessor methods, then re-encode before storing; this keeps the test aligned with the meta-value format and avoids magic offsets.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/storage/tests/redis_vector_test.rs` around lines 458 - 467, Update the
test setup around the retrieved meta value to decode it with VectorMeta::decode,
mutate the stale TTL-related fields through the type’s accessor methods rather
than hard-coded byte offsets, then re-encode the VectorMeta before storing it
with put_cf. Preserve the intended previous generation and expired TTL values
while keeping the test aligned with the encode/decode format.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/superpowers/plans/2026-07-19-redis-vector-set.md`:
- Around line 44-51: Update Task 6 to reference the vector module layout under
src/cmd/src/vector/, using vector/mod.rs for shared parsing, helpers, and
registration tests plus separate modules for each command; remove or replace the
conflicting instruction to create src/cmd/src/vector.rs. Apply the same path
correction to the additionally affected section.

---

Nitpick comments:
In `@src/storage/src/format_vector.rs`:
- Around line 134-201: Add a regression case to the vector metadata
malformed-bytes test, `vector_codecs_reject_malformed_bytes`, that mutates the
metric byte at offset 19 to an unsupported value and asserts
`VectorMeta::decode` returns an error. Keep the existing format-byte case and
target the `SimilarityMetric::from_u8` validation path.

In `@src/storage/src/vector.rs`:
- Around line 182-204: Add a concise explanatory comment in ScoredCandidate::cmp
documenting that the score ordering is intentionally reversed so
BinaryHeap::peek() exposes the worst top-k candidate, while the element
tie-break remains in its existing direction. Do not alter the comparison
behavior.

In `@src/storage/tests/redis_vector_test.rs`:
- Around line 458-467: Update the test setup around the retrieved meta value to
decode it with VectorMeta::decode, mutate the stale TTL-related fields through
the type’s accessor methods rather than hard-coded byte offsets, then re-encode
the VectorMeta before storing it with put_cf. Preserve the intended previous
generation and expired TTL values while keeping the test aligned with the
encode/decode format.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c1b7e87-d210-4d07-b742-02e28caf3c58

📥 Commits

Reviewing files that changed from the base of the PR and between 05148c0 and 5e0e972.

📒 Files selected for processing (20)
  • docs/superpowers/plans/2026-07-19-redis-vector-set.md
  • src/cmd/src/lib.rs
  • src/cmd/src/vector/mod.rs
  • src/cmd/src/vector/vadd.rs
  • src/cmd/src/vector/vcard.rs
  • src/cmd/src/vector/vdim.rs
  • src/cmd/src/vector/vemb.rs
  • src/cmd/src/vector/vismember.rs
  • src/cmd/src/vector/vrem.rs
  • src/cmd/src/vector/vsim.rs
  • src/net/src/executor_ext.rs
  • src/net/tests/storage_command_e2e_tests.rs
  • src/resp/src/encode.rs
  • src/resp/tests/resp2_encoding.rs
  • src/storage/src/format_member_data_key.rs
  • src/storage/src/format_vector.rs
  • src/storage/src/lib.rs
  • src/storage/src/redis_vectors.rs
  • src/storage/src/vector.rs
  • src/storage/tests/redis_vector_test.rs
💤 Files with no reviewable changes (1)
  • src/cmd/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/storage/src/lib.rs

Comment thread docs/superpowers/plans/2026-07-19-redis-vector-set.md Outdated
happy-v587 and others added 7 commits July 26, 2026 17:03
Restore the flag constant so the bit remains reserved, even though
vector commands no longer use it.

Co-Authored-By: Claude <noreply@anthropic.com>
…-db#356

- Document reversed score ordering in HeapHit::cmp.
- Add regression test for unsupported vector metric byte.
- Expose VectorMeta accessors and use decode/encode in tests.
- Delegate RESP encoding to version-aware append_* helpers.

Co-Authored-By: Claude <noreply@anthropic.com>
Keep remote VectorSearchEngine / SimilarityMetric additions and resolve
the outstanding CodeRabbit review fixes:

- format_vector.rs: keep SimilarityMetric + metric field, keep encode/decode
  public for integration tests, preserve metric-byte regression test.
- redis_vectors.rs: accept remote removal of HeapHit; search is now delegated
  to VectorSearchEngine.
- vector.rs: add BinaryHeap top-k retention comment to ScoredCandidate::cmp.

Co-Authored-By: Claude <noreply@anthropic.com>
- merge the private encode_resp_data_inner into the RespEncode trait
  method; version handling stays inline at the encoding points
- translate the vector-set plan doc to Chinese and update Step 3 to
  match the merged encoder design
- move vector value layout comments next to their struct definitions
# Conflicts:
#	src/net/src/executor_ext.rs
- CanonicalVector now holds quantized data (VectorData: Fp32/Binary/Int8)
  with to_quantized() as the single conversion entry point
- score() dispatches per quantization: hamming similarity for BIN,
  cosine on the dequantized FP32 form otherwise
- VectorDataValue format v3: quant byte, reserved flags byte (for
  future SETATTR attributes), per-quantization payload layouts
- VectorMeta carries the set-level quantization; vadd/vsim convert
  members and queries to the set's quantization
- unify vector meta reads via decode_vector_meta/read_vector_meta_opt
- move parse_vadd/parse_vsim/parse_vemb and their tests from
  vector/mod.rs into the respective command modules; mod.rs keeps
  only the shared helpers
- parse_vadd becomes a keyword option loop matching the Redis syntax:
  NOQUANT/Q8/BIN are wired to quantization (default NOQUANT), while
  CAS/EF/SETATTR/M/REDUCE are rejected with dedicated errors
- add Redis syntax comments to vector command arity definitions
Comment thread src/net/src/executor_ext.rs Dismissed
Comment thread src/storage/src/batch.rs Outdated
Comment thread src/storage/src/storage_manifest.rs
Comment thread src/server/src/main.rs Outdated
Comment thread src/storage/src/storage_scan.rs
Comment thread src/storage/src/format_base_value.rs
@happy-v587

Copy link
Copy Markdown
Collaborator Author

PR 改动总结

这个 PR 是一次完整的 Redis Vector Set 第一阶段实现,不是单纯增加几个命令,因此改动范围较大:共涉及 75 个文件,约 +10,590 / -290 行。

主要改动包括:

  1. 新增 Vector Set 命令

    • VADDVSIMVREMVCARDVDIMVEMBVINFOVISMEMBER
    • 包括参数解析、命令注册、错误处理和 INFO VECTOR 统计信息。
  2. 新增 VectorSet 存储层

    • VectorSet 元数据和成员数据结构
    • VectorDataCF 列族
    • Vector member key 和元数据编码/解码
    • 维度、元素大小和类型校验
    • generation/storage incarnation 生命周期隔离,避免旧成员被新对象误读。
  3. 增加 Flat Vector Search

    • 暴力扫描、距离计算、结果排序
    • 查询超时、取消检查、并发容量限制和扫描上限
    • 查询统计指标及 INFO VECTOR 输出。
  4. 增加量化框架

    • 支持 NOQUANTBINQ8 的协议和数据结构框架。
    • 部分量化选项仍按第一阶段范围返回暂不支持。
  5. 接入删除、过期和 compaction 生命周期

    • DEL 通过 VectorSet 元数据 tombstone 进行逻辑删除
    • 使用 version/generation 防止旧成员重新可见
    • compaction 时清理 VectorDataCF 中的过期成员
    • 支持 SCAN TYPE vectorsetRANDOMKEY、过期和重建场景。
  6. 增加 Raft 和集群相关基础能力

    • VectorSet mutation v1、binlog/slot 处理、snapshot schema 扩展
    • 节点 capability 查询和集群能力检查。
    • 由于当前物理 binlog 回放仍存在 Vector member incarnation 在 failover 后不可读的问题,集群模式默认拒绝 Vector 命令;vector-cluster-enabled 仅用于测试/开发绕过,不代表正式支持集群 Vector。
  7. RESP2/RESP3 兼容

    • 增加 Vector 查询结果的 RESP2/RESP3 编码适配
    • 补充 null、double、big number、verbatim string 等类型编码测试。
  8. 配置和测试

    • 新增 Vector 维度、大小、查询并发、超时和扫描限制等配置。
    • 增加 storage、编码、compaction、生命周期、RESP、Python 命令兼容和三节点 Raft 测试。

改动行数主要集中在 VectorSet 存储格式、命令实现、生命周期/compaction 处理,以及约 3,000 行以上的新增测试代码;整体是跨命令层、协议层、存储层和集群层的完整数据类型落地。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants