Knowledge Base API
A KnowledgeBase is a stateful container that lets Synalinks programs persist and retrieve structured knowledge through a pluggable storage backend. It pairs a JSON schema (derived from your DataModels) with a database adapter that handles the underlying I/O: SQL stores via the Database Adapters (DuckDB, LanceDB) and graph stores via the Graph Database Adapters (LadybugDB, Relate). The URI picks the adapter.
Knowledge bases are the storage layer used by knowledge-aware modules such as EmbedKnowledge, UpdateKnowledge, and RetrieveKnowledge, and they back higher-level agents like VectorRAGAgent and SQLAgent.
import synalinks
import asyncio
class Document(synalinks.DataModel):
title: str = synalinks.Field(
description="The document title",
)
content: str = synalinks.Field(
description="The document content",
)
async def main():
embedding_model = synalinks.EmbeddingModel(
model="ollama/mxbai-embed-large",
)
knowledge_base = synalinks.KnowledgeBase(
uri="duckdb://:memory:",
data_models=[Document],
embedding_model=embedding_model,
)
if __name__ == "__main__":
asyncio.run(main())
Knowledge Base API overview
Database Adapters
Graph Database Adapters
Choosing a store
A KnowledgeBase has a SQL side (uri=) and a graph side (graph_uri=); each URI selects its adapter. All adapters of a side expose the same methods and return the same results, so switching is a one-line change.
| Side | URI | Adapter | Choose it when |
|---|---|---|---|
| SQL | duckdb://... (default) |
DuckDB | General purpose: full-text, vector, regex and hybrid search, raw SQL, encryption at rest, in-memory mode for tests. |
| SQL | lancedb://... |
LanceDB | Vector-heavy workloads: native vector search over columnar Lance datasets. SELECT queries still work (DuckDB reads the Lance tables). |
| Graph | ladybug://... (default) |
LadybugDB | General purpose property graph: typed node and edge tables, Cypher, vector and full-text search, graph algorithms (PageRank, communities) for GraphRAG. |
| Graph | relate://... |
Relate by Neo4j | You want Neo4j's Cypher dialect and Lucene full-text, embedded with no server. Schema-free labels; graph algorithms run through networkx. Needs pip install 'synalinks[relate]'. |