Unified memory engine for AI applications - SQLite for AI memory (CPU build)
Project description
MnemeFusion Python Bindings
Python bindings for MnemeFusion - a unified memory engine for AI applications.
Installation
From Source (Development)
cd mnemefusion-python
pip install maturin
maturin develop
From PyPI (when published)
pip install mnemefusion
Quick Start
import mnemefusion
# Open or create a database
memory = mnemefusion.Memory("brain.mfdb", config={
"embedding_dim": 384,
"entity_extraction_enabled": True,
})
# Add a memory
memory_id = memory.add(
"Meeting scheduled for March 15th",
embedding=[0.1] * 384, # Your embedding vector
metadata={"type": "event"}
)
# Semantic search
results = memory.search(query_embedding, top_k=10)
for mem, score in results:
print(f"{score:.3f}: {mem['content']}")
# Intelligent query with intent classification
intent, results = memory.query(
"Why was the meeting cancelled?",
query_embedding,
limit=10
)
print(f"Intent: {intent['intent']} ({intent['confidence']:.2f})")
for mem, scores in results:
print(f"Fused score: {scores['fused_score']:.3f}")
print(f"Content: {mem['content']}")
# Close the database
memory.close()
Using Context Manager
with mnemefusion.Memory("brain.mfdb") as memory:
memory.add("Some content", embedding)
# Database automatically closed when exiting
API Reference
Memory Class
__init__(path, config=None)
Create or open a memory database.
Parameters:
path(str): Path to the .mfdb fileconfig(dict, optional): Configuration optionsembedding_dim(int): Dimension of embedding vectors (default: 384)entity_extraction_enabled(bool): Enable automatic entity extraction (default: True)
Returns: Memory instance
add(content, embedding, metadata=None, timestamp=None)
Add a new memory to the database.
Parameters:
content(str): Text contentembedding(List[float]): Vector embeddingmetadata(Dict[str, str], optional): Key-value metadatatimestamp(float, optional): Unix timestamp (seconds since epoch)
Returns: Memory ID as string
get(memory_id)
Retrieve a memory by ID.
Parameters:
memory_id(str): Memory ID
Returns: Dictionary with memory data, or None if not found
Memory dict structure:
{
"id": str,
"content": str,
"embedding": List[float],
"metadata": Dict[str, str],
"created_at": float # Unix timestamp
}
delete(memory_id)
Delete a memory by ID.
Parameters:
memory_id(str): Memory ID
Returns: bool - True if deleted, False if not found
search(query_embedding, top_k)
Semantic similarity search.
Parameters:
query_embedding(List[float]): Query vectortop_k(int): Number of results to return
Returns: List of (memory_dict, similarity_score) tuples
query(query_text, query_embedding, limit)
Intelligent multi-dimensional query with intent classification.
Parameters:
query_text(str): Natural language queryquery_embedding(List[float]): Query vectorlimit(int): Maximum number of results
Returns: Tuple of (intent_dict, results_list)
intent_dict:{"intent": str, "confidence": float}results_list: List of (memory_dict, scores_dict) tuples
Scores dict structure:
{
"semantic_score": float,
"temporal_score": float,
"causal_score": float,
"entity_score": float,
"fused_score": float
}
Intent types:
"Temporal": Time-based queries ("yesterday", "recent")"Causal": Cause-effect queries ("why", "because")"Entity": Entity-focused queries ("about X", "mentioning Y")"Factual": Generic semantic search
count()
Get the number of memories in the database.
Returns: int - Count of memories
add_causal_link(cause_id, effect_id, confidence, evidence)
Add a causal relationship between two memories.
Parameters:
cause_id(str): Memory ID of the causeeffect_id(str): Memory ID of the effectconfidence(float): Confidence score (0.0 to 1.0)evidence(str): Text explaining the relationship
get_causes(memory_id, max_hops)
Get causes of a memory (backward traversal).
Parameters:
memory_id(str): Memory IDmax_hops(int): Maximum traversal depth
Returns: List of causal paths (each path is a list of memory ID strings)
get_effects(memory_id, max_hops)
Get effects of a memory (forward traversal).
Parameters:
memory_id(str): Memory IDmax_hops(int): Maximum traversal depth
Returns: List of causal paths (each path is a list of memory ID strings)
list_entities()
List all entities in the database.
Returns: List of entity dictionaries
Entity dict structure:
{
"id": str,
"name": str,
"mention_count": int,
"metadata": Dict[str, str]
}
close()
Close the database and save all indexes.
Examples
See examples/basic_usage.py for a comprehensive example.
Requirements
- Python >= 3.8
- Rust toolchain (for building from source)
License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mnemefusion_cpu-0.1.4.tar.gz.
File metadata
- Download URL: mnemefusion_cpu-0.1.4.tar.gz
- Upload date:
- Size: 340.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d766a741eae272781bf02df66239c765e79fcff6194624ac5671a4ecdbdc838
|
|
| MD5 |
9e40a67ac84fed5db904a58d64f3c92f
|
|
| BLAKE2b-256 |
8afda2401a83ed12dd37e969c8aa6d5ee948bcab13bbd7b0dc861daacc102793
|
File details
Details for the file mnemefusion_cpu-0.1.4-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: mnemefusion_cpu-0.1.4-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
437d3b3d4b02afd98f9f6f66e8498dc1e3e85803e5ad684657b6d93759108504
|
|
| MD5 |
af90ae6491df635f6cc943b5cdb35277
|
|
| BLAKE2b-256 |
368399fb9366b5576ea392ac183980fa096840584d62dc84dca2e4c960d1d566
|
File details
Details for the file mnemefusion_cpu-0.1.4-cp312-cp312-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: mnemefusion_cpu-0.1.4-cp312-cp312-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.12, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a087f3b9e2d0ff39fc8545a65453b9e692d495ee64c5685510333cf01d425bd3
|
|
| MD5 |
bf45b952eef2f1a8becad9f24c2524e5
|
|
| BLAKE2b-256 |
828798749be29ba2522ab81857407f2eb6a86dca6bab68a7cef8e4542272766f
|
File details
Details for the file mnemefusion_cpu-0.1.4-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: mnemefusion_cpu-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f412b12281d4d23772278d2252cc38eef9c5b87477ad64ec1126985406d74978
|
|
| MD5 |
d0724affd10fd58e3058668a17bfea25
|
|
| BLAKE2b-256 |
78ab9b4baf1da2bd15ec1e17f88bdc037852740677914bb06a21bf3691005076
|
File details
Details for the file mnemefusion_cpu-0.1.4-cp312-cp312-macosx_10_15_x86_64.whl.
File metadata
- Download URL: mnemefusion_cpu-0.1.4-cp312-cp312-macosx_10_15_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.12, macOS 10.15+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21bff6b038b03193b86f0e47ba5dcfa85a8da2b3f8ab59da8986b07e21444cdd
|
|
| MD5 |
c3d3283bc97d6f73c1de15993163094a
|
|
| BLAKE2b-256 |
6f5cdf16c5c0cf168976c64fd47d487fe0396f8826ee4ee8e3db37376465aadc
|