-
Notifications
You must be signed in to change notification settings - Fork 34
Add namespace-scoped collections with IVF vector indexing for agent database #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
8b7a956
pyseekdb collection支持按namespace隔离
JingYuChe c4897dd
pyseekdb支持设置namespace_id相关的session缓存
JingYuChe da41d77
代码检视问题修改
JingYuChe 5f0e1a9
delete
JingYuChe f7f6b1c
pyseekdb修改ob的search index with parser
JingYuChe ca1a069
新增 namespace 统计 catalog 表
LYAccc ef3d119
Merge pull request #1 from JingYuChe/feat/sdk-namespaces-stats
JingYuChe 0622ed9
prewarm集成测试用例加强
JingYuChe 5eb9b44
提供set_namespace_partition_count动态设置分区数
JingYuChe 2d901a4
屏蔽hybrid_search用search_para解析成sql,直接向内核输入hybrid_search接口
JingYuChe 750f581
混搜支持data_content过滤
JingYuChe 0c62edc
kv table到key 改为varbinary
JingYuChe 765dcee
namespace.add,get等操作显示设置session
JingYuChe 941a0c9
namespace.add,get等操作显示设置session
JingYuChe 4ee60df
pyseekdb新增dbms_logic_table.drop_namespace用例
JingYuChe 69542a1
logic table id采用真实分配的值
JingYuChe 33ab2c3
fts适配default_operator:and
JingYuChe 17743d8
Fix conflict
skylhd 4ae23cd
or修复
JingYuChe 5d10d73
修复json_search双引号问题
JingYuChe 4afb949
add namespace case
skylhd dafc36d
Merge branch 'develop' of https://github.com/skylhd/pyseekdb into adb…
skylhd 13c0101
修复scalar term query in must/should clause not supported
JingYuChe f82317f
fix dsl
skylhd accc8ef
sdk改名
JingYuChe 6ea284c
fix(hybrid_search): hoist $not_contains must_not out of scoring bool …
JingYuChe ee11730
open spfresh and add case
skylhd 65bf56c
open spfresh and add case
skylhd 79c0b9c
fix conflict
skylhd c18230d
fix case
skylhd 17f89a1
fix(hybrid_search): hoist metadata $ne/$nin must_not for FTS and KNN …
JingYuChe a555bdc
drop namespace联调sdk适配修改
JingYuChe 6d7ffb6
fix(hybrid_search): replace exists with OB-compatible positive must_n…
JingYuChe 78c3d55
prewarm_lob sdk适配
JingYuChe db373ac
Merge branch 'develop' of https://github.com/JingYuChe/pyseekdb into …
skylhd 227fdb3
add cosine case
skylhd d67cbfb
prewarm_lob sdk适配
JingYuChe c564ff9
fix case
skylhd c77f23b
修query里面有向量查询SDK要转成DSL
JingYuChe 9df48f6
fix case
skylhd 1ee5a99
del print
skylhd e2e0da1
Merge branch 'develop' of https://github.com/JingYuChe/pyseekdb into …
skylhd 181fecf
Merge pull request #2 from skylhd/develop
JingYuChe 551e351
ss模式和sn模式逻辑表向量索引随表创建
JingYuChe 0a722a7
用户自定义创建向量,全文索引
JingYuChe 94dcf5f
set_namespace_partition_count接口改名
JingYuChe 52dcbad
ob内核版本拦截+只支持ivf_flat拦截
JingYuChe 9e284ee
add prewarm for namespace test case
skylhd 4a6cd4b
Merge branch 'develop' of https://github.com/JingYuChe/pyseekdb into …
skylhd da44ebe
fix run
skylhd 591a413
Merge pull request #3 from skylhd/develop
JingYuChe ad3697a
fix:【pyseekdb】collection被删除之后,仍能执行ns = coll.create_namespace
JingYuChe 81b36cf
fix:【pyseekdb】namespace删除后,执行ns.add,仍旧执行成功
JingYuChe 28b7d92
fix:[pyseekdb][namespace] get_collection 打开带 embedding_function setti…
JingYuChe 210c2d1
设置分区数改为collection粒度,改成create collection的配置项
JingYuChe 553c861
fix:n_results值有误在sdk直接报错
JingYuChe 1454126
update与collection场景保持一下
JingYuChe d3c3879
测试用例embedding用例修复
JingYuChe c1cdef5
fix:[pyseekdb]创建collection过程中,ob重启情况下,再次创建collection第一次创建会失败
JingYuChe fb708d2
fix:去掉drop_namespace的mock
JingYuChe c9b44b6
更新centroids_fresh_mode名适配内核
JingYuChe c77839e
fix_drop_table
JingYuChe c27ea4a
fix:除data_table意外默认使用index表
JingYuChe 3e5676d
Merge remote-tracking branch 'origin/develop' into develop
JingYuChe 626caca
pyseekdb对外ivf参数fresh_mode改为centroids_fresh_mode
JingYuChe dff351f
fix:【AgentDB/逻辑表】并发 get_or_create_namespace 同名 namespace 不幂等,唯一键冲突 1062
JingYuChe d16c80e
fix:【pyseekdb】并发执行ns.upsert,保存多行相同ids
JingYuChe 0be3947
fix:多个client并发执行delete_collection与has_collection,出现不一致
JingYuChe 8b50723
fix:issue_fix
JingYuChe 444d4ba
fix:
JingYuChe f874066
fix:【pyseekdb】 创建namespcae报错1235,应该是obproxy不支持get_lock函数问题
JingYuChe c688423
Docstring 覆盖率修复
JingYuChe 4d4d0dc
fix:【pyseekdb】对于没有物理表的collection,仍旧可以get到,并且能够创建namespace
JingYuChe 9139b9e
fix:review
JingYuChe dde32f1
docstring_add
JingYuChe a9d0f59
fix:【pyseekdb】非法 include 字段没有报错
JingYuChe 081d24f
fix:【pyseekdb】sdk没有对内核报错进行包装
JingYuChe 908186a
fix:【pyseekdb】ns.query支持的where_document操作符不完全
JingYuChe a0c9599
fix:issue
JingYuChe 513a33a
fix:【pyseekdb】ob内核不支持ivf索引超越2048维,但是sdk给的范围是[1,4096]
JingYuChe b39abbd
fix:【pyseekdb】 不传入向量索引配置的时候,向量列是sdk内部指定的384维,ns.add报错信息不明确
JingYuChe e06c500
issue_fix
JingYuChe 251eb05
ut适配collection_dimension
JingYuChe 7abf5c7
非namespace路径不去校验_validate_include
JingYuChe ec803f2
dont run namespace testcases on workflow
JingYuChe b59159a
import:_validate_namespace_name
JingYuChe 843e8bd
fix_quality
JingYuChe 6d2f357
skip_lakebase
JingYuChe 15ab7fc
namespace模式只支持lakebase
JingYuChe dc95767
适配内核计算lob头
JingYuChe 6860dbd
fix_workflow
JingYuChe b071f5d
fix_issue_hnwyllmm
JingYuChe 7811b2b
without ignore
JingYuChe 3546102
quality_fix
JingYuChe fb2c7cf
fix_test
JingYuChe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Namespace Collections | ||
|
|
||
| Namespace collections partition data inside a single physical collection. Each **namespace** is a logical slice (similar to a tenant or dataset) that shares catalog tables and IVF-backed vector indexes, while keeping documents isolated by `namespace_id`. | ||
|
|
||
| **Requirements** | ||
|
|
||
| - LakeBase **4.6.1.0** or newer (`OceanBase Database AI` in `SELECT version()`) | ||
| - `use_namespace=True` when creating the collection | ||
| - An explicit **IVF** `Schema` (the default non-namespace path builds **HNSW**, which namespace collections do not support) | ||
|
|
||
| ## 1. Create a namespace-enabled collection | ||
|
|
||
| ```python | ||
| import pyseekdb | ||
| from pyseekdb import IVFConfiguration, FulltextIndexConfig, VectorIndexConfig, Schema | ||
|
|
||
| client = pyseekdb.Client(host="127.0.0.1", port=2881, database="test") | ||
|
|
||
| schema = Schema( | ||
| vector_index=VectorIndexConfig( | ||
| ivf=IVFConfiguration(dimension=384, distance="cosine", centroids_fresh_mode="spfresh"), | ||
| embedding_function=None, # or pass your embedding function | ||
| ), | ||
| fulltext_index=FulltextIndexConfig(analyzer="ik"), | ||
| ) | ||
|
|
||
| collection = client.create_collection( | ||
| name="products", | ||
| schema=schema, | ||
| use_namespace=True, | ||
| partition_count=4, # optional; controls table partitioning | ||
| ) | ||
| ``` | ||
|
|
||
| If you omit `schema` with `use_namespace=True`, pyseekdb raises a clear error instead of silently building the default HNSW schema. | ||
|
|
||
| **Not supported yet** | ||
|
|
||
| - Default / HNSW schemas (`configuration=HNSWConfiguration(...)` without an IVF `Schema`) | ||
| - `SparseVectorIndexConfig` on namespace collections | ||
|
|
||
| ## 2. Manage namespaces | ||
|
|
||
| ```python | ||
| ns = collection.create_namespace("electronics") | ||
| # or idempotently: | ||
| ns = collection.get_or_create_namespace("electronics") | ||
|
|
||
| collection.list_namespaces() # ["electronics", ...] | ||
| collection.delete_namespace("electronics") | ||
| ``` | ||
|
|
||
| ## 3. Add and query data inside a namespace | ||
|
|
||
| Namespace DML uses **record ids** — per-document business keys you pass as `ids` in `namespace.add()`, `get()`, `update()`, and `delete()`. They are stored in `data_content.id` (JSON), not as the table primary key. | ||
|
|
||
| ```python | ||
| ns.add( | ||
| ids=["doc_1", "doc_2"], | ||
| embeddings=[[0.1, 0.2, 0.3], [0.4, 0.5, 0.6]], | ||
| documents=["phone", "laptop"], | ||
| metadatas=[{"brand": "A"}, {"brand": "B"}], | ||
| ) | ||
|
|
||
| rows = ns.get(ids=["doc_1"], include=["documents", "metadatas"]) | ||
| hits = ns.query(query_embeddings=[[0.1, 0.2, 0.3]], n_results=5) | ||
| ``` | ||
|
|
||
| **Record id rules (namespace path)** | ||
|
|
||
| - Must be non-empty strings | ||
| - Currently limited to `[A-Za-z0-9_]` (letters, digits, underscore) | ||
| - Maximum length 512 characters | ||
|
|
||
| Standard (non-namespace) collections accept broader `_id` values (for example UUIDs with hyphens). If you need UUID-style ids on the namespace path, normalize them (for example `doc_a1b2c3d4`) or wait for a future relaxation. | ||
|
|
||
| ## 4. `get_or_create_collection` compatibility | ||
|
|
||
| `get_or_create_collection(..., use_namespace=...)` must match how the collection was originally created: | ||
|
|
||
| ```python | ||
| # OK — reuses the existing namespace collection | ||
| client.get_or_create_collection("products", schema=schema, use_namespace=True) | ||
|
|
||
| # Raises ValueError — name already used by a standard HNSW collection | ||
| client.get_or_create_collection("legacy_coll", use_namespace=True) | ||
| ``` | ||
|
|
||
| Delete the old collection or pick a new name when switching between standard and namespace modes. | ||
|
|
||
| ## 5. Collection-level hybrid search | ||
|
|
||
| Namespace collections also expose `collection.hybrid_search(...)` across namespaces. See integration examples under `tests/integration_tests/test_namespace_*.py` for FTS + vector patterns. | ||
|
|
||
| ## See also | ||
|
|
||
| - [Collection management](collection-management.md) — standard HNSW collections | ||
| - [DML operations](dml.md) — `add` / `update` / `delete` on standard collections | ||
| - `examples/namespace_example.py` — minimal runnable sample |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| """ | ||
| Namespace collection example (LakeBase 4.6.1.0+). | ||
|
|
||
| Demonstrates: | ||
| 1. Creating a namespace-enabled collection with an explicit IVF schema | ||
| 2. Creating a namespace and adding documents with record ids | ||
| 3. Vector query inside the namespace | ||
| """ | ||
|
|
||
| import pyseekdb | ||
| from pyseekdb import FulltextIndexConfig, IVFConfiguration, Schema, VectorIndexConfig | ||
|
|
||
| # Connect to LakeBase / OceanBase (adjust host/port/credentials) | ||
| client = pyseekdb.Client( | ||
| host="127.0.0.1", | ||
| port=2881, | ||
| database="test", | ||
| user="root@test", | ||
| password="", | ||
| ) | ||
|
|
||
| schema = Schema( | ||
| vector_index=VectorIndexConfig( | ||
| ivf=IVFConfiguration(dimension=3, distance="l2", centroids_fresh_mode="spfresh"), | ||
| embedding_function=None, | ||
| ), | ||
| fulltext_index=FulltextIndexConfig(analyzer="ik"), | ||
| ) | ||
|
|
||
| collection_name = "demo_namespace_collection" | ||
| collection = client.create_collection( | ||
| name=collection_name, | ||
| schema=schema, | ||
| use_namespace=True, | ||
| partition_count=4, | ||
| ) | ||
|
|
||
| ns = collection.get_or_create_namespace("demo") | ||
|
|
||
| # Record ids are per-document keys inside this namespace (see docs/guide/namespace.md). | ||
| ns.add( | ||
| ids=["item_alpha", "item_beta"], | ||
| embeddings=[[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]], | ||
| documents=["alpha product", "beta product"], | ||
| metadatas=[{"tier": "a"}, {"tier": "b"}], | ||
| ) | ||
|
|
||
| results = ns.query(query_embeddings=[[1.0, 0.0, 0.0]], n_results=2, include=["documents", "metadatas"]) | ||
| print("Top match:", results["ids"][0][0], results["documents"][0][0]) | ||
|
|
||
| collection.delete_namespace("demo") | ||
| client.delete_collection(collection_name) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.