Skip to content

Low-level storage API providing direct access to SQLite, FAISS, and graph operations. Used internally by AriadneMemory — use this API for advanced operations.

Constructor

python
from arriadne import AriadneDB, AriadneConfig

config = AriadneConfig(db_path="memory.db", embedding_dim=384)
db = AriadneDB(config)
db.open()

Context Manager

python
with AriadneDB(AriadneConfig(db_path="memory.db")) as db:
    db.add_memory("Hello", memory_type="semantic")
# Automatically closed on exit

open()

Open the database connection, create schema, and load FAISS index.

python
db.open()

TIP

Called automatically on first use if not called explicitly.

close()

Close the database connection and save the FAISS index to disk.

python
db.close()

add_memory()

Add a new memory to the database. Handles FAISS indexing and entity association.

python
result = db.add_memory(
    content="User prefers dark mode",
    embedding=np.array([...], dtype=np.float32),
    memory_type="semantic",
    importance=0.8,
    entities=["user", "preferences"],
    metadata={"category": "ui"},
)

Parameters

ParameterTypeDefaultDescription
contentstrrequiredText content
embeddingnp.ndarray | NoneNoneEmbedding vector (auto L2-normalized)
memory_typestr"semantic"Memory category
importancefloat0.5Importance score (0.0–1.0)
entitieslist[str] | NoneNoneEntity names to associate
metadatadict | NoneNoneJSON-serializable metadata

Returns

python
{"memory_id": int, "status": "created" | "duplicate"}

Behavior

  1. Computes SHA-256 content hash for exact dedup
  2. Checks for existing memory with same hash
  3. L2-normalizes embedding if provided
  4. Inserts into memories table
  5. Adds to FAISS index
  6. Auto-upgrades FAISS from FlatIP to IVFFlat if threshold exceeded
  7. Associates entities via memory_entities table

get_memory()

Retrieve a memory by ID. Automatically updates access tracking.

python
memory = db.get_memory(memory_id=42)

Returns

python
{
    "id": int,
    "content": str,
    "content_hash": str,
    "memory_type": str,
    "importance": float,
    "created_at": float,
    "updated_at": float,
    "accessed_at": float,
    "access_count": int,
    "retention_strength": float,
    "is_deleted": bool,
    "metadata": dict | None,
}

WARNING

Each call to get_memory() increments access_count and updates accessed_at, affecting retention scoring.


update_memory()

Update an existing memory's fields.

python
success = db.update_memory(
    memory_id=42,
    content="Updated content",
    importance=0.9,
    embedding=new_embedding,
    metadata={"updated": True},
)

Parameters

ParameterTypeDefaultDescription
memory_idintrequiredMemory to update
contentstr | NoneNoneNew content (updates hash)
importancefloat | NoneNoneNew importance
embeddingnp.ndarray | NoneNoneNew embedding
metadatadict | NoneNoneNew metadata

Returns

boolTrue if updated, False if not found.


delete_memory()

Delete a memory (soft or hard).

python
success = db.delete_memory(memory_id=42, hard=False)

Parameters

ParameterTypeDefaultDescription
memory_idintrequiredMemory to delete
hardboolFalseTrue for permanent delete

Soft Delete

Sets is_deleted = 1 and records deleted_at. Memory is excluded from search but data is preserved.

Hard Delete

Permanently removes from memories, memory_entities, memory_links, and access_log tables.


Search by vector similarity using FAISS.

python
results = db.vector_search(query_embedding, k=10)

Parameters

ParameterTypeDefaultDescription
embeddingnp.ndarrayrequiredQuery embedding (auto L2-normalized)
kint10Number of results

Returns

list[dict] — Memory dicts with score (inner product similarity) and search_type: "vector".


Full-text keyword search using SQLite FTS5.

python
results = db.fts_search("deploy production", k=10)

Parameters

ParameterTypeDefaultDescription
querystrrequiredSearch query
kint10Number of results

Returns

list[dict] — Memory dicts with score (BM25 rank) and search_type: "fts".


Hybrid search combining vector and FTS with Reciprocal Rank Fusion.

python
results = db.hybrid_search(
    query="deploy production",
    embedding=query_embedding,
    k=10,
    rrf_k=60,
)

Parameters

ParameterTypeDefaultDescription
querystrrequiredFTS query text
embeddingnp.ndarray | NoneNoneVector query (optional)
kint10Number of results
rrf_kint60RRF smoothing parameter

Returns

list[dict] — Memory dicts with score (RRF fused score) and search_type: "hybrid".

RRF Formula

$$\text{score}(d) = \sum_{r \in R} \frac{1}{k + \text{rank}_r(d)}$$


add_edge()

Add a directed edge between two entities.

python
db.add_edge("Ariadne", "FAISS", edge_type="uses", weight=1.0)

Parameters

ParameterTypeDefaultDescription
source_entitystrrequiredSource entity name
target_entitystrrequiredTarget entity name
edge_typestr"related"Relationship type
weightfloat1.0Edge weight

traverse_graph()

BFS traversal from an entity using recursive CTEs.

python
result = db.traverse_graph("Ariadne", hops=3, edge_type="uses")

Parameters

ParameterTypeDefaultDescription
entity_namestrrequiredStarting entity
hopsint1Max depth (capped at max_graph_depth)
edge_typestr | NoneNoneFilter by edge type

Returns

python
{
    "nodes": list[str],
    "edges": [{"source": str, "target": str, "type": str, "weight": float}]
}

Retention & Priority Scoring

compute_retention_strength()

Compute Ebbinghaus retention: R = e^(-t/S).

python
memory = db.get_memory(42)
R = db.compute_retention_strength(memory)
FactorFormula
tnow - memory["accessed_at"]
Sretention_half_life × importance
Rexp(-t / S)

compute_priority_score()

Weighted priority score.

python
priority = db.compute_priority_score(memory)
ComponentFormula
importanceDirect value (0.0–1.0)
recency1 / (1 + age_days)
access_normmin(1, access_count / 100)
retentionEbbinghaus retention strength
Priorityw_imp × importance + w_rec × recency + w_acc × access_norm + w_ret × retention

evict()

Evict lowest-priority memories via soft delete.

python
evicted = db.evict()

Behavior

  1. Count active memories
  2. Compute budget: max(1, int(total × eviction_budget))
  3. Score all active memories
  4. Sort by priority (ascending)
  5. Soft-delete the bottom budget memories

Returns

int — Number of memories evicted.


consolidate()

Group similar memories using Jaccard similarity and create consolidation records.

python
groups = db.consolidate()

Behavior

  1. Load up to 5,000 active memories
  2. Tokenize content into word sets
  3. Compute Jaccard similarity between all pairs
  4. Group memories with similarity ≥ consolidation_threshold
  5. Create consolidation records (content joined by |)

Returns

int — Number of consolidation groups created.


stats()

Get comprehensive database statistics.

python
stats = db.stats()

Returns

python
{
    "total_memories": int,
    "active_memories": int,
    "deleted_memories": int,
    "by_type": dict[str, int],
    "total_entities": int,
    "total_edges": int,
    "total_memory_links": int,
    "total_consolidations": int,
    "faiss_vectors": int,
    "faiss_type": str,
    "faiss_dimension": int,
    "avg_importance": float,
    "db_size_bytes": int,
}

Released under the MIT License.