Overview
AI + vector search as SQL, inside Postgres.
TheoDB is a PostgreSQL 17 distribution that puts AI — embeddings, generation,
ranking, natural-language queries — and vector search into the database as plain
SQL functions. It is not a fork or a new engine: it composes upstream
PostgreSQL with a curated set of extensions (a customized pgvector,
pgvectorscale) plus its own Rust extension, so one CREATE EXTENSION exposes an
ai.* / theodb.* surface. You generate embeddings, run vector + hybrid search,
and call an LLM directly in SQL — against the same transactional rows as your
operational data, with no ETL to a separate vector store.
TheoDB is a commercial product, pre-1.0 and in active development. It is
available via early access — request access at
usetheo.dev/theodb. No production-ready claim is
made yet, and TheoDB makes no speed/throughput superiority claim over pgvector
or ScaNN (parity at best on the recall × QPS frontier).
The AI surface, in SQL
Once the extension is enabled, AI is just SQL. The database ships no model and stores no keys — you point it at any OpenAI-compatible endpoint via session settings.
CREATE EXTENSION IF NOT EXISTS theodb CASCADE; -- pulls vector + vectorscale
-- Embeddings
SELECT theodb.embed('running shoes for trail'); -- → vector
-- Generation / classification, per row
SELECT ai.summarize(description) AS gist,
ai.analyze_sentiment(review) AS mood
FROM products;The unified query is the point — vector search, a relational JOIN, and an AI call in one transaction:
SELECT p.id, p.description,
ai.summarize(p.description) AS gist -- AI leg
FROM products p
JOIN inventory i ON i.product_id = p.id -- relational JOIN
WHERE i.in_stock AND p.category_id = 3 -- relational filter
ORDER BY p.embedding <=> '[0.1, 0.2, ...]'::vector -- vector leg
LIMIT 5;Capabilities
AI in SQL
`theodb.embed` / `embed_batch`, `ai.generate`, `ai.summarize`, `ai.analyze_sentiment`, `ai.rank`, and `ai.agg_summarize` (collapse many rows into one summary) — model-agnostic, configured per session.
Hybrid search (RRF)
`ai.hybrid_search(...)` fuses Postgres full-text search and vector legs with Reciprocal Rank Fusion — one function, injection-safe.
Safe NL → SQL
`ai.nl_query(question, allowed_relations)` generates, validates, and runs a query in a read-only sandbox — layered anti-prompt-injection (SELECT-only, parser-grade relation allowlist, sandbox raising on any write).
Vector indexes
Standard `pgvector` HNSW / IVFFlat and `pgvectorscale` StreamingDiskANN, plus TheoDB's own persisted access methods and SBQ / PQ quantization — coexisting, not competing.
Search modes
Semantic (`embedding <=> query`), hybrid (FTS + vector, RRF), and filtered (recall-preserving iterative scans).
Migrate from Pinecone
`theodb.import_vectors` / `import_vectors_chunked` map `{id, values, metadata}` exports into a relational table — one database for data and vectors.
Columnar / HTAP is on the roadmap (decided and benchmarked), not yet in the shipped extension surface. AI calls are synchronous per row (one HTTP round-trip) — plan for cost and latency accordingly.