mormot2-pgvector
A Pascal library for vector search and Retrieval Augmented Generation (RAG) over Pascal source code, built on mORMot 2, PostgreSQL, and pgvector.
What does it do
Take a folder of Pascal source files. Get back a chatbot that knows your code.
.pas .pp .dpr files "How does TOrm serialize to JSON?"
│ │
▼ chunker ▼ embed query
chunks with vector
metadata │
│ ▼
▼ embed (Ollama) hybrid retrieval
vectors (cosine + tsvector)
│ │
▼ INSERT ▼
PostgreSQL top-K chunks
(HNSW + GIN) │
▼ LLM call
answer with
file:line citations
Why does it exist
When you ask a generic LLM about a niche framework like mORMot 2, it hallucinates. The training data is too thin. RAG fixes this by grounding the answer in actual code retrieved at query time.
This project ports the pgvector-go binary wire format to Pascal so the same database can serve Pascal-native applications, Go services, Python notebooks, or anything that speaks pgvector. You stay inside the mORMot 2 ecosystem (one language, one ORM, one HTTP stack) while reusing the broader vector-DB tooling.
What you get
- Three CLI programs:
01_ingest_mormot2,02_query_cli,03_chat_cli— drop-in tools you can pipe into a script. - A Pascal library:
TPgVectorcodec, embedding-client interface, Pascal source chunker, RAG orchestrator, ORM helper. Use them directly in your own .dpr / .lpr program. - Production primitives: persistent HTTP transport with configurable timeouts, exponential-backoff retries, concurrency cap decorator, parallel ingest with thread-local embedders, thread-safe PostgreSQL connection pool.
What it isn't
- Not a fine-tune of an LLM — the model is unmodified; we feed it retrieved context at query time.
- Not a full-text search engine — it complements PostgreSQL's own
tsvectorrather than replacing it; the hybrid retrieval blends both. - Not Docker-only — every piece runs as a native binary on Windows, Linux, and macOS.
Status
Production-ready for the documented use case. 60 / 60 build-site tasks
completed; 2 674 / 2 674 unit-test assertions PASSED on Windows + FPC,
Windows + Delphi 12, and Linux + FPC (WSL Ubuntu 24.04). Live tests
verified end-to-end against PostgreSQL 18.3 + pgvector 0.8 and Ollama
(embeddinggemma:300m + gemma4:e2b).
License
MIT.