pgvector for Arkiv: similarity search over vectors stored on-chain, behind one REST call
Your RAG embeddings are a row in someone else's database. One expired credit card and your retrieval layer has amnesia.
Arkivector is pgvector for Arkiv.
pgvector is the Postgres extension with more than 23,000 GitHub stars, and it is one of the most widely used pieces of RAG infrastructure there is. It adds vector similarity search to the database you already run, so retrieval becomes one line: ORDER BY embedding <=> $1 LIMIT 5. No new service, no new query language. Now that agentic AI is everywhere, RAG matters more than ever. Agents need to look things up before they act, and pgvector sits underneath a huge share of those retrieval pipelines.
Arkiv is a chain built for data, roughly "SQL on web3". Entities have typed attributes, an owner, and an expiry block, and you query them with a filter language instead of decoding raw contract storage. As far as I could find, it had no vector search. You could store an embedding there as bytes, but you could not ask which entities are closest to it. So I rebuilt pgvector for Arkiv, using pgvector's own C code for the math.
Your app calls client.upsert(...). The daemon encodes the vector, signs an Arkiv transaction, and sends it. It mines on Arkiv, and the daemon indexes it once it reads it back from the chain. Then client.search(vector=..., k=5, filter=...) returns the nearest entities, ranked by L2, cosine, inner product, L1, Hamming, or Jaccard distance, in a single REST call, and there is an MCP endpoint so an AI agent can call search as a tool.
Why Arkiv is the point, not a checkbox:
Your RAG embeddings live on-chain. Nobody can delete or reprice them behind your back, and any Arkiv client can read them without Arkivector being online.
Arkiv's expiry is native. When an entity's expiry block passes, it drops out of search automatically—a built-in data retention policy with no cron job required.
Every search answer includes the block height, so you know exactly how fresh a result is.
The daemon is only a cache; if you wipe it, it rebuilds the whole index from Arkiv.
I tested all of this end-to-end. An upsert landed on-chain in under three seconds, synced back, and filtered vector search returned the right neighbours through both SDKs.
It is honest about its limits. Searches currently perform an exact scan, which is correct but slow on huge collections. pgvector's HNSW graph is compiled into the daemon, and wiring it to collections is next.
The math is pgvector's actual C code, not a rewrite. The daemon is C11, because pgvector is C. The distance kernels, half-precision conversion, sparse and bit routines, and HNSW graph code are copied from pgvector 0.8.7 and compiled in unchanged, apart from a few marked lines, all listed in a provenance file. pgvector expects PostgreSQL around it (palloc, ereport, fmgr, lightweight locks), so I wrote a compatibility layer. palloc allocates from per-request arenas. ereport(ERROR) unwinds to a setjmp boundary and becomes an ordinary API error. A CI job diffs the copied files against upstream so they cannot drift. A parity suite of 97 tests runs the daemon's distances against real pgvector 0.8.7 in Postgres, and every result is bit-identical or within float32 rounding. Kernels are compiled once per CPU level (baseline, AVX2/FMA, AVX-512, aarch64) and picked at startup.
Arkiv does the hard parts.
Storage: Each item is a plain Arkiv entity with reserved attributes: a schema tag, an id, the vector as bytes, and the document. A halfvec(768) costs 1,544 bytes on chain.
Syncing: A syncer thread bootstraps a collection through arkiv_query, then follows the chain through eth_getLogs on the Arkiv contract. It keeps a ring of recent block hashes to detect reorgs and roll back, and it runs periodic count checks to catch drift. Idle, it costs one cheap poll per block.
Writes: The writer ABI-encodes execute((uint8,bytes)[]) calls, signs EIP-1559 transactions with secp256k1, and submits them. Arkiv's real contract accepts them. The first Rabdi write reverted until I found that the operation payload needs a 0x20 head offset, so the daemon runs on the live chain, not just my mock.
Storage and Filtering Entities live in memory-mapped segment files in pgvector's in-memory index. Attribute filters compile to roaring bitmaps "live at this block" before any distance is computed, using a worker pool so a slow scan never blocks the loop.
The Slightly Hacky Bits I wrote a custom node simulator with reorgs, expiry, and fault injection, so there is no behavior I cannot reproduce on demand. Everything is fuzzed: RPC, filters, vector literals, transaction calldata. It caught an allocation bug in the calldata decoder within seconds.
An architecture film is generated at build time and played in the browser with Web Audio rather than shipped as a file process. The project was developed spec-first: the architecture and the API contracts were written before the code, with proposals and task lists in the repository and reviewed against those specs. CI enforces them with clang-tidy, cppcheck, sanitizers, fuzzers, and a 163-integration test suite. A tag-triggered pipeline publishes the Linux container to GHCR and the Python package to PyPI via trusted publishing, alongside GitHub Packages.
Left to Do (Stated Plainly) Searches are currently exact scans. Signing uses a key in an environment variable, with user-wallet signing planned through the existing unsigned transaction pathway. It has only been run on the Rabdi testnet.

