kci_vec_pg
kci-vec · KCI-Vec approximate nearest-neighbor search
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 102415 | kci_vec_pg | kci-vec | 0.3 | RAG | MIT | C |
PostgreSQL · 15, 16, 17
Usage
Sources:
kci_vec_pg exposes KCI-Vec approximate nearest-neighbor search through SQL functions. SQL version 0.3 is a prototype tested on PostgreSQL 15–17 on Linux x86-64. The reviewed library is 0.2.25 while SQL remains 0.3. The library has used MIT since 0.2.15; releases through 0.2.14 retain their original PolyForm terms. Vector index images are external files, so backups and standby operation require explicit handling.
Build and Search
Create the extension as a superuser, then build from a table whose ID casts to bigint and whose vector casts to real arrays:
The build supports cosine, squared Euclidean distance and inner product. Search returns IDs and scores; cosine and inner-product scores increase with similarity, while squared distances decrease. Larger probe and rerank settings trade work for recall. An overload accepts an allowed-ID array for filtering. The planner does not automatically choose this search through a PostgreSQL index access method.
Changes and Maintenance
kci_vec_track() records inserts, updates, deletes and truncation in ordinary tables; searches merge pending changes, including the caller’s transaction. kci_vec_refresh() folds them into the image. Large backlogs slow searches. kci_vec_untrack() stops tracking; kci_vec_drop() removes an index.
Optional preload enables cheaper change tracking and the background worker:
Changing preload requires a restart; retain existing library entries. The ordinary function interface does not require this setup. The separate vector extension is optional; install it before this extension when its vector-type overloads are wanted.
Recovery and Limits
Images under $PGDATA/kci_vec/ are outside WAL and pg_dump, and are not encrypted by the extension. A restored database or standby must rebuild its local image with kci_vec_materialize(); searches reject a missing or outdated image. kci_vec_image_here() checks local presence. Builds and refreshes run only on the primary.
Call kci_vec_drop() before removing the extension because dropping it does not remove images. The documented upgrade procedure installs new files, restarts PostgreSQL and runs ALTER EXTENSION kci_vec_pg UPDATE. NULL IDs or vectors are skipped. Very selective filters may need more probes or an exact SQL search. Interfaces and catalog tables may change while this remains a prototype.
Probe Settings and Current Validation
nprobe = 0 selects a single-threaded exact scan; the default nprobe = 32 remains approximate. Version 0.2.25 fixes duplicate-vector scoring and tie handling. Performance on larger inputs remains unproven; validate correctness, recall and resource cost with your own data rather than treating the library version or exact mode as a scalability guarantee.