Building RAG & Knowledge Bases with seekdb: Three Paths, One Stack
Source: Dev.to
The real headache in RAG isn’t retrieval or generation—it’s the layer in between. Where does the data live? How do you keep it in sync? Who glues it all together? seekdb and Dify are both open‑source, so your RAG stack—from storage to orchestration—can be self‑hosted, auditable, and customizable without locking you into closed services. This post walks through three paths, all built on one stack:
- RAG from scratch with seekdb
- Dify + seekdb
- A knowledge‑base desktop app
Pick the one that fits and get it running.
A Typical RAG Pipeline
load documents → chunk → embed → store
query time: retrieve → (optional) rerank → feed to LLM → generateIf your storage is a patchwork of MySQL, a vector DB, and a full‑text engine, you end up managing sync, multi‑source queries, and fusion yourself. seekdb’s role is to provide one database that holds relational data, vectors, and full‑text in the same place. Write once, index automatically; a single hybrid query returns results. You can also use in‑database AI functions for embedding and reranking, so storage and retrieval live in one layer with far less glue code.
Three Paths
| Path | When it’s the best fit |
|---|---|
| RAG from scratch with seekdb | Full control over the pipeline or an existing Python/app stack |
| Dify + seekdb | Want Dify for orchestration/UI while using seekdb as the knowledge‑base backend |
| Knowledge‑base desktop application | Need a local, multi‑project desktop app with seekdb as the backend and a custom frontend |
1. Deploy and Create Tables
Run seekdb in Embedded or Client/Server mode. Create a table (or Python collection) with vector and full‑text columns, then add the appropriate indexes.
CREATE TABLE documents (
id BIGINT PRIMARY KEY,
chunk_text TEXT,
embedding VECTOR(768), -- adjust dimension to your model
metadata JSONB
);
CREATE VECTOR INDEX idx_documents_embedding ON documents (embedding);
CREATE FULLTEXT INDEX idx_documents_text ON documents (chunk_text);2. Load Documents
- Read docs (PDF, TXT, MD, …).
- Chunk them (by paragraph, length, with overlap, etc.).
- For each chunk, obtain an embedding vector. You can:
- Call seekdb’s in‑database AI functions, or
- Compute embeddings in your app and insert them.
# Example using a Python client
from seekdb import SeekDBClient
client = SeekDBClient(...)
for chunk in chunks:
vector = embed_model.encode(chunk.text) # or client.embed(chunk.text)
client.execute(
"""
INSERT INTO documents (chunk_text, embedding, metadata)
VALUES (%s, %s, %s)
""",
(chunk.text, vector, {"source": chunk.source, "doc_id": chunk.doc_id})
)3. Query Time
- Convert the user question to a query vector (same embedding model).
- Perform a hybrid search: vector similarity + optional full‑text query + relational filters (e.g., knowledge‑base ID).
- Retrieve the top‑k candidates.
- (Optional) Rerank with seekdb or in your app.
- Pass the final context to your LLM to generate the answer.
SELECT id, chunk_text, metadata
FROM documents
WHERE hybrid_search(
query_vector => $1,
query_text => $2, -- optional
filters => $3 -- e.g. {"kb_id": 42}
)
ORDER BY score DESC
LIMIT 10;4. Things to Watch
- Chunking strategy and chunk size directly affect recall—experiment and tune.
- Using in‑database AI for embedding/reranking eliminates round‑trips to external services.
- For a complete walkthrough with code, see the guide “Build a RAG application with seekdb.”
Dify + seekdb Integration
Dify handles workflow orchestration, knowledge‑base setup, and the chat UI. When configured to use seekdb as the data source:
- Upload / parse → Dify chunks the documents.
- Dify calls the embedding service (or its own) and writes vectors + metadata into seekdb.
- At query time, Dify sends the user question to seekdb, receives hybrid‑search results, and forwards them to the LLM node for the final answer.
Result: no separate sync scripts or multi‑database juggling—the stack is simply “Dify config + seekdb.”
For details, see the article “Dify + seekdb: Collapsing the RAG Stack.”
Knowledge‑Base Desktop Application
If you prefer a local solution (multiple projects, multiple docs, offline search):
- Use seekdb as the backend API.
- Build a desktop client with Tauri, Electron, or any framework of your choice.
- The flow mirrors the previous paths: parse → chunk → embed → write to seekdb; at query time, perform hybrid search and display results or feed them to a local LLM.
Official guide: “Building a knowledge‑base desktop app with seekdb.” It outlines the stack and step‑by‑step instructions.
What’s Next?
Once you have RAG or a knowledge base running with seekdb, the next post will explore extending the stack beyond text—multimodal and agent‑based use cases such as travel assistants, image search, and voice assistants.
Resources
- Repository: (Apache 2.0)
- Documentation:
- Discord:
- Medium:
- Press release: “OceanBase Releases seekdb” – MarkTechPost