Skip to content

feat: 支持以只读模式打开已有 zvec#12

Merged
hustcc merged 5 commits into
masterfrom
zvec-readonly
Jul 10, 2026
Merged

feat: 支持以只读模式打开已有 zvec#12
hustcc merged 5 commits into
masterfrom
zvec-readonly

Conversation

@yvonneyx

Copy link
Copy Markdown
Contributor

当前 Context 在访问某个 library 时,如果对应的 .zvec 文件不存在,会自动创建新的 zvec 文件;同时
load() 会写入或更新向量数据。

但在一些使用场景中,zvec 文件已经由构建流程、离线任务或其他服务提前生成,线上/消费端进程只需要查询,不应该
再创建或修改向量文件。

变更内容

  • 新增 ContextOptions.readOnly 配置,用于声明当前 Context 只消费已有 zvec
  • 只读模式下,查询会通过 ZVecOpen 打开已有 ${library}.zvec
  • 如果目标 zvec 不存在,不再自动创建,而是抛出明确错误
  • 只读模式下禁止 load() 和写入操作,避免运行时意外修改向量数据
  • 补充 README 示例和 Store 层测试

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a readOnly configuration option to the Context and Store classes, allowing users to query existing .zvec files without mutating them or creating missing stores. In read-only mode, any write operations (such as load() or addDoc()) or attempts to open non-existent stores will throw an error. The feedback suggests wrapping the store cleanup in try...finally blocks within the new unit tests to ensure resources are always closed even if assertions fail.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread test/storage/store.test.ts
Comment thread test/storage/store.test.ts
yvonneyx and others added 2 commits July 10, 2026 11:42
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@hustcc

hustcc commented Jul 10, 2026

Copy link
Copy Markdown
Member

增加 readonly 是解决什么问题?

如果真的需要 readonly,应该是 ZevcOpen 调用的时候,传入 readonly 就可以,这样不用自己去做 throw。

@hustcc hustcc merged commit 7480906 into master Jul 10, 2026
2 checks passed
@hustcc hustcc deleted the zvec-readonly branch July 10, 2026 13:34
@hustcc

hustcc commented Jul 10, 2026

Copy link
Copy Markdown
Member

验证对的,确实需要 readonly 模式,也验证了直接使用 zvec 的 readonly 效果一致,就不外置判断 readonly,自己 throw 了。

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.

2 participants