Feat v0.8.3 vector column type (#70)
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-runners (pull_request) Has been skipped
CI/CD / e2e-smoke (pull_request) Has been skipped
CI/CD / build-and-deploy (pull_request) Has been cancelled
CI/CD / test-sqlite (pull_request) Has been cancelled
CI/CD / test-go-pg (pull_request) Has been cancelled
Some checks failed
CI/CD / detect-changes (pull_request) Successful in 4s
CI/CD / test-frontend (pull_request) Has been skipped
CI/CD / test-runners (pull_request) Has been skipped
CI/CD / e2e-smoke (pull_request) Has been skipped
CI/CD / build-and-deploy (pull_request) Has been cancelled
CI/CD / test-sqlite (pull_request) Has been cancelled
CI/CD / test-go-pg (pull_request) Has been cancelled
Add vector(N) column type to db_tables manifests with three-tier progressive enhancement: native pgvector on Postgres, JSONB fallback without pgvector, TEXT fallback on SQLite. New db.query_similar() Starlark builtin with dual-path dispatch. - parseVectorDim validates 1..4096 dimensions - mapColType gains hasPgvector parameter for tier selection - HNSW index auto-created on pgvector backends - starlarkToGoValue extended with list→JSON serialization - cosineDistance helper for Go-side fallback computation - ExtensionHandler gains SetCapabilities for install-time DDL - Roadmap updated: v0.8.4 docs refresh + surface sizing fix 13 new tests (5 schema + 8 db module), all passing with -race. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -136,6 +136,33 @@ results = db.query_batch([
|
||||
# Each query spec supports: table (required), filters, order, limit, before, after, search_like
|
||||
```
|
||||
|
||||
#### Vector similarity search
|
||||
|
||||
```python
|
||||
# Find rows with the most similar embeddings (cosine distance)
|
||||
rows = db.query_similar(
|
||||
"documents", # table name
|
||||
"embedding", # vector column name
|
||||
vector=[0.1, 0.2, ...], # query vector (list of floats)
|
||||
limit=10, # max results (default 10, max 100)
|
||||
filters={"active": True}, # optional equality filters
|
||||
metric="cosine", # only "cosine" supported
|
||||
)
|
||||
# Returns rows ordered by ascending _distance (0.0 = identical, 1.0 = orthogonal)
|
||||
# Each row dict includes an injected "_distance" float key.
|
||||
```
|
||||
|
||||
Vector columns are declared as `"vector(N)"` in the manifest `db_tables` block
|
||||
(N = dimension, 1–4096). Storage varies by backend:
|
||||
|
||||
| Backend | Column type | Search |
|
||||
|---------|-------------|--------|
|
||||
| Postgres + pgvector | `vector(N)` with HNSW index | Native `<=>` operator |
|
||||
| Postgres (no pgvector) | `JSONB` | Go-side cosine computation |
|
||||
| SQLite | `TEXT` | Go-side cosine computation |
|
||||
|
||||
Insert vectors as lists: `db.insert("docs", {"embedding": [0.1, 0.2, 0.3]})`.
|
||||
|
||||
#### Write operations
|
||||
|
||||
```python
|
||||
|
||||
Reference in New Issue
Block a user