Python API
YantrikDB
Section titled “YantrikDB”The main database class.
Constructor
Section titled “Constructor”db = YantrikDB(db_path="memory.db", embedding_dim=384)| Parameter | Type | Default | Description |
|---|---|---|---|
db_path | str | "memory.db" | Path to the database file |
embedding_dim | int | 384 | Embedding vector dimensions |
Core Methods
Section titled “Core Methods”record(text, **kwargs)
Section titled “record(text, **kwargs)”Store a memory.
db.record( "User likes Python", importance=0.7, # 0.0-1.0 valence=0.3, # -1.0 to 1.0 (emotional) memory_type="semantic", # episodic, semantic, procedural domain="work", source="user",)recall(query, top_k=10, **kwargs)
Section titled “recall(query, top_k=10, **kwargs)”Retrieve memories using relevance-conditioned scoring.
results = db.recall( "What programming languages?", top_k=5, memory_type="semantic", # optional filter namespace="default", # optional filter)Returns a list of dicts with text, score, rid, importance, valence, etc.
relate(src, dst, rel_type, weight=1.0)
Section titled “relate(src, dst, rel_type, weight=1.0)”Create a relationship in the cognitive graph.
db.relate("Pranab", "Walmart", "works_at", weight=0.9)think(**kwargs)
Section titled “think(**kwargs)”Run autonomous cognition: consolidation, conflict detection, pattern mining, triggers.
result = db.think( importance_threshold=0.5, run_consolidation=True, run_conflict_scan=True, run_pattern_mining=True,)Returns a dict with triggers, consolidation_count, conflicts_found, patterns_new, duration_ms.
forget(rid)
Section titled “forget(rid)”Tombstone a memory by record ID.
db.forget("019d0a1b-...")stats()
Section titled “stats()”Get database statistics.
s = db.stats()# s['active_memories'], s['edges'], s['entities'], etc.Graph Methods
Section titled “Graph Methods”entities()
Section titled “entities()”List all entities in the cognitive graph.
edges(entity=None)
Section titled “edges(entity=None)”List edges, optionally filtered by entity.
conflicts()
Section titled “conflicts()”List all detected contradictions.
patterns()
Section titled “patterns()”List all discovered behavioral patterns.
Embedding
Section titled “Embedding”set_embedder(fn)
Section titled “set_embedder(fn)”Set the embedding function.
from sentence_transformers import SentenceTransformermodel = SentenceTransformer("all-MiniLM-L6-v2")db.set_embedder(lambda text: model.encode(text).tolist())