Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 7 additions & 13 deletions docs/en/development/memory-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,14 @@ the same citation fields through list and exact-read operations.
unavailable. Explicit `vector` and `hybrid` requests fail when the configured profile does not provide that
capability.

## Enable SQLite Vec1
## Enable SQLite vector search

SQLite vector search is enabled only when both a Vec1 0.7 or newer loadable extension and an embedding model are
supplied. PowerContext does not install or build the native extension; provide a compatible library for the target
operating system and architecture:
SQLite vector search is enabled when an embedding model is supplied. The `powercontext[builtin]` extra bundles
`sqlite-vec`, so no extension path or separate native-library installation is required:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

[P2] Update the RFC contracts for sqlite-vec

The runtime contract now replaces Vec1 and removes vec1_extension, but the English and Chinese copies of RFCs 0014, 0019, and 0020 still prescribe Vec1, its extension path, and vec1(...) table/query semantics. Readers now get incompatible setup and schema descriptions from the checked-in documentation. Please update both locale copies as part of this breaking change.


```python
from pathlib import Path

config = BuiltinConfig(
database=SQLiteConfig(
url="sqlite+aiosqlite:///powercontext.db",
vec1_extension=Path("/opt/sqlite-extensions/vec1"),
)
database=SQLiteConfig(url="sqlite+aiosqlite:///powercontext.db")
)
async with open_builtin_runtime(
config,
Expand All @@ -112,7 +106,7 @@ async with open_builtin_runtime(
...
```

The SQLite profile composes FTS5 and Vec1 strategies. It reports `fts`, `vector`, and `hybrid` through Memory
The SQLite profile composes FTS5 and sqlite-vec strategies. It reports `fts`, `vector`, and `hybrid` through Memory
capabilities.
Stored projections and query vectors must use the same `EmbeddingProfile`, including model name, dimension, distance,
and normalization. Changing that profile requires rebuilding projections before vector search resumes.
Expand Down Expand Up @@ -145,7 +139,7 @@ async with open_builtin_runtime(

The OceanBase profile uses the same index composition as SQLite. Its full-text strategy is always available. Supplying
an embedding model adds a `VECTOR` projection and HNSW strategy, enabling `vector` and `hybrid` modes. SQLite FTS5 and
OceanBase FULLTEXT therefore serve the same Runtime and Server search calls; Vec1 and HNSW do the same for vector
OceanBase FULLTEXT therefore serve the same Runtime and Server search calls; sqlite-vec and HNSW do the same for vector
search.

## Operational checks
Expand All @@ -155,7 +149,7 @@ Before serving requests, verify:
- the selected profile opens and initializes successfully;
- each tenant or project maps to the intended scope ID;
- scheduled extraction has a candidate pipeline;
- Vec1 configuration includes a matching embedding model;
- SQLite vector search has a matching embedding model;
- OceanBase vector search has a matching embedding model;
- capability responses match the indexes actually initialized;
- database and scheduler resources close with the process lifecycle.
11 changes: 5 additions & 6 deletions docs/en/development/pydantic-ai-inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ Vector search needs the embedding model and its complete deployment profile:
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_MODEL="provider:embedding-model"
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_PROFILE_ID="project-embedding-v1"
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_DIMENSION="1536"
export POWERCONTEXT_SERVER_DATABASE_VEC1_EXTENSION="/opt/sqlite-extensions/vec1"
```

Provider credentials remain in the environment variables understood by the selected Pydantic AI provider. They are
not fields on PowerContext models.

The Server rejects a partial embedding profile. `embedding_model`, `embedding_profile_id`, and `embedding_dimension`
must be configured together. Vec1 also requires that embedding configuration because the index dimension and stored
vectors must agree.
must be configured together. SQLite vector search uses that embedding configuration because the index dimension and
stored vectors must agree.

## Compose generation directly

Expand Down Expand Up @@ -99,9 +98,9 @@ embedding_model = PydanticAIEmbeddingModel(
)
```

Pass this adapter to `open_builtin_contexts()` or `open_builtin_runtime()` with a `SQLiteConfig` that selects the Vec1
extension. The adapter verifies output count, order, dimension, and finite numeric values, then applies the declared
unit normalization before vectors reach persistence.
Pass this adapter to `open_builtin_contexts()` or `open_builtin_runtime()` with a `SQLiteConfig`. The bundled
sqlite-vec index is enabled automatically. The adapter verifies output count, order, dimension, and finite numeric
values, then applies the declared unit normalization before vectors reach persistence.

An `EmbeddingProfile` is a deployment contract, not descriptive metadata. Stored projections and query embeddings
must use the same profile. When the model, dimension, or normalization changes, rebuild Memory projections from the
Expand Down
2 changes: 1 addition & 1 deletion docs/en/development/remote-access-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export POWERCONTEXT_SERVER_DATABASE_KIND="oceanbase"
export POWERCONTEXT_SERVER_DATABASE_URL="mysql+aoceanbase://user:password@host:2881/powercontext?charset=utf8mb4"
```

Both database choices expose full-text search through the same Server API. With an embedding model, SQLite uses Vec1
Both database choices expose full-text search through the same Server API. With an embedding model, SQLite uses sqlite-vec
and OceanBase uses HNSW for `vector` and `hybrid` searches.

Inference configuration is documented in [Configure Pydantic AI inference](pydantic-ai-inference.md).
Expand Down
16 changes: 6 additions & 10 deletions docs/en/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,33 +178,29 @@ Optional settings are `POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_NORMALIZATION` an

Embedding normalization defaults to `unit`.

### SQLite Vec1
### SQLite vector search

SQLite vector and hybrid search additionally require a
[SQLite Vec1](https://sqlite.org/vec1/doc/trunk/doc/vec1.md) 0.7 or newer loadable extension. PowerContext does not
download, build, or update this native library. Obtain it for the Server's operating system and architecture, then
set its path together with the complete embedding profile:
SQLite vector and hybrid search use [sqlite-vec](https://alexgarcia.xyz/sqlite-vec/), which is bundled with the
`powercontext[builtin]` dependency set. Configure the complete embedding profile; no extension path is needed:

```bash
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_MODEL=provider:embedding-model
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_PROFILE_ID=embedding-model-v1
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_DIMENSION=1024
export POWERCONTEXT_SERVER_DATABASE_URL=sqlite+aiosqlite:////srv/powercontext/powercontext.db
export POWERCONTEXT_SERVER_DATABASE_VEC1_EXTENSION=/opt/sqlite-extensions/vec1
powercontext server run
```

The extension path must identify a library that the SQLite loader can open. PowerContext loads and probes the
extension when the Server opens the database; startup fails if the library is incompatible or older than 0.7.
PowerContext loads and probes the bundled extension when the Server opens the database. Startup fails if the package
does not contain a library compatible with the current platform or SQLite build.

In another terminal, confirm that the initialized runtime reports vector and hybrid search:

```bash
powercontext capabilities
```

If Vec1 is unavailable, leave `POWERCONTEXT_SERVER_DATABASE_VEC1_EXTENSION` unset. SQLite full-text search remains
available without an embedding model or native extension.
SQLite full-text search remains available when no embedding model is configured.

## CLI Server connection

Expand Down
19 changes: 7 additions & 12 deletions docs/zh/development/memory-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,14 @@ operation 返回相同的 citation 字段。
`mode="auto"` 会选择当前可用的最强模式,并可在 query embedding 暂时不可用时回退到 FTS。显式请求 `vector`
或 `hybrid` 时,如果 profile 没有提供相应能力,操作会失败。

## 启用 SQLite Vec1
## 启用 SQLite 向量检索

只有同时提供 0.7 或更高版本的 Vec1 loadable extension 和 embedding model,SQLite 才会启用向量检索。
PowerContext 不负责安装或构建这个 native extension;请提供适用于目标操作系统和架构的 library:
提供 embedding model,SQLite 会启用向量检索。`powercontext[builtin]` 已捆绑 `sqlite-vec`,无需配置 extension
路径或单独安装 native library:

```python
from pathlib import Path

config = BuiltinConfig(
database=SQLiteConfig(
url="sqlite+aiosqlite:///powercontext.db",
vec1_extension=Path("/opt/sqlite-extensions/vec1"),
)
database=SQLiteConfig(url="sqlite+aiosqlite:///powercontext.db")
)
async with open_builtin_runtime(
config,
Expand All @@ -109,7 +104,7 @@ async with open_builtin_runtime(
...
```

SQLite profile 会组合 FTS5 和 Vec1 strategy,并通过 Memory capabilities 报告 `fts`、`vector` 和 `hybrid`。持久化
SQLite profile 会组合 FTS5 和 sqlite-vec strategy,并通过 Memory capabilities 报告 `fts`、`vector` 和 `hybrid`。持久化
projection 与 query vector 必须使用同一个 `EmbeddingProfile`,包括 model name、dimension、distance 和
normalization。更换 profile 后,应先重建 projection,再恢复 vector search。

Expand Down Expand Up @@ -141,7 +136,7 @@ async with open_builtin_runtime(

OceanBase profile 与 SQLite 使用相同的 index 组合方式。全文 strategy 始终可用;提供 embedding model 后,会增加
`VECTOR` projection 和 HNSW strategy,并启用 `vector` 与 `hybrid` mode。SQLite FTS5 与 OceanBase FULLTEXT
服务于同一组 Runtime 和 Server search 调用,Vec1 与 HNSW 也通过同一接口提供向量检索。
服务于同一组 Runtime 和 Server search 调用,sqlite-vec 与 HNSW 也通过同一接口提供向量检索。

## 运行检查

Expand All @@ -150,7 +145,7 @@ OceanBase profile 与 SQLite 使用相同的 index 组合方式。全文 strateg
- 所选 profile 能够成功打开并完成初始化;
- 每个 tenant 或 project 映射到预期的 scope ID;
- 定时 extraction 已经配置 candidate pipeline;
- Vec1 配置包含匹配的 embedding model;
- SQLite vector search 配置了匹配的 embedding model;
- OceanBase vector search 配置了匹配的 embedding model;
- capability response 与实际初始化的 index 一致;
- database 和 scheduler 资源会随进程生命周期关闭。
7 changes: 3 additions & 4 deletions docs/zh/development/pydantic-ai-inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ vector search 需要 embedding model 和完整的 deployment profile:
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_MODEL="provider:embedding-model"
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_PROFILE_ID="project-embedding-v1"
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_DIMENSION="1536"
export POWERCONTEXT_SERVER_DATABASE_VEC1_EXTENSION="/opt/sqlite-extensions/vec1"
```

provider credential 仍使用所选 Pydantic AI provider 支持的环境变量,不属于 PowerContext model 字段。

Server 会拒绝不完整的 embedding profile。`embedding_model`、`embedding_profile_id` 和
`embedding_dimension` 必须一起配置。Vec1 也依赖这组配置,因为 index dimension 必须与持久化向量一致。
`embedding_dimension` 必须一起配置。SQLite vector search 使用这组配置,因为 index dimension 必须与持久化向量一致。

## 直接组合 generation

Expand Down Expand Up @@ -95,8 +94,8 @@ embedding_model = PydanticAIEmbeddingModel(
)
```

将这个 adapter 传给 `open_builtin_contexts()` 或 `open_builtin_runtime()`,并通过 `SQLiteConfig` 选择 Vec1
extension。向量进入持久化之前,adapter 会校验输出数量、顺序、dimension 和数值有效性,并执行 profile 声明的单位归一化。
将这个 adapter 与 `SQLiteConfig` 一起传给 `open_builtin_contexts()` 或 `open_builtin_runtime()` 后,会自动启用捆绑的
sqlite-vec index。向量进入持久化之前,adapter 会校验输出数量、顺序、dimension 和数值有效性,并执行 profile 声明的单位归一化。

`EmbeddingProfile` 是 deployment contract,不是描述性 metadata。持久化 projection 和 query embedding 必须使用
同一个 profile。model、dimension 或 normalization 发生变化后,应从权威 Memory revision 重建 projection。
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/development/remote-access-implementation.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export POWERCONTEXT_SERVER_DATABASE_KIND="oceanbase"
export POWERCONTEXT_SERVER_DATABASE_URL="mysql+aoceanbase://user:password@host:2881/powercontext?charset=utf8mb4"
```

两种 database 都通过同一组 Server API 提供全文检索。配置 embedding model 后,SQLite 使用 Vec1,OceanBase
两种 database 都通过同一组 Server API 提供全文检索。配置 embedding model 后,SQLite 使用 sqlite-vec,OceanBase
使用 HNSW 提供 `vector` 和 `hybrid` 检索。

inference 配置见[配置 Pydantic AI 推理](pydantic-ai-inference.md)。
Expand Down
16 changes: 6 additions & 10 deletions docs/zh/docs/reference/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,33 +172,29 @@ export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_DIMENSION=1024

Embedding normalization 默认为 `unit`。

### SQLite Vec1
### SQLite 向量检索

SQLite vector 和 hybrid search 还需要 0.7 或更高版本的
[SQLite Vec1](https://sqlite.org/vec1/doc/trunk/doc/vec1.md) loadable extension。PowerContext 不负责下载、构建或更新
这个 native library。请先获取适用于 Server 操作系统和架构的构建产物,再同时配置 extension 路径和完整的
embedding profile:
SQLite vector 和 hybrid search 使用 [sqlite-vec](https://alexgarcia.xyz/sqlite-vec/),它已包含在
`powercontext[builtin]` 依赖中。只需配置完整的 embedding profile,无需配置 extension 路径:

```bash
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_MODEL=provider:embedding-model
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_PROFILE_ID=embedding-model-v1
export POWERCONTEXT_SERVER_INFERENCE_EMBEDDING_DIMENSION=1024
export POWERCONTEXT_SERVER_DATABASE_URL=sqlite+aiosqlite:////srv/powercontext/powercontext.db
export POWERCONTEXT_SERVER_DATABASE_VEC1_EXTENSION=/opt/sqlite-extensions/vec1
powercontext server run
```

extension 路径必须指向 SQLite loader 可以打开的 library。Server 打开数据库时,PowerContext 会加载并探测该
extension;如果 library 不兼容或版本低于 0.7,启动会失败。
Server 打开数据库时,PowerContext 会加载并探测捆绑的 extension;如果当前 platform 或 SQLite build 与 package
中的 library 不兼容,启动会失败。

在另一个终端确认初始化后的 Runtime 已报告 vector 和 hybrid search:

```bash
powercontext capabilities
```

如果没有可用的 Vec1,请不要设置 `POWERCONTEXT_SERVER_DATABASE_VEC1_EXTENSION`。即使没有 embedding model 或
native extension,SQLite full-text search 仍然可用。
没有配置 embedding model 时,SQLite full-text search 仍然可用。

## CLI Server 连接

Expand Down
2 changes: 2 additions & 0 deletions e2e/bub/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ builtin = [
"pydantic-settings>=2.7,<3",
"pyobvector>=0.2.28,<0.3",
"sqlalchemy[asyncio]>=2,<3",
"sqlite-vec>=0.1.9,<0.2",
]
client = [
"httpx[socks]>=0.28,<1",
Expand Down
Loading
Loading