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
Metadata
Release files for mnemefusion-cpu 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mnemefusion_cpu-0.1.4.tar.gz | 340.5 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| mnemefusion_cpu-0.1.4-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| mnemefusion_cpu-0.1.4-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| mnemefusion_cpu-0.1.4-cp312-cp312-macosx_11_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 11.0+ ARM64 | Details |
| mnemefusion_cpu-0.1.4-cp312-cp312-macosx_10_15_x86_64.whl | CPython 3.12 | CPython 3.12 | macOS 10.15+ x86-64 | Details |
Total release size: 12.5 MB
Release files / mnemefusion_cpu-0.1.4.tar.gz
| Download URL | mnemefusion_cpu-0.1.4.tar.gz |
|---|---|
| Size | 340.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d766a741eae272781bf02df66239c765e79fcff6194624ac5671a4ecdbdc838
|
|
BLAKE2b-256 checksum How to use checksums |
8afda2401a83ed12dd37e969c8aa6d5ee948bcab13bbd7b0dc861daacc102793
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / mnemefusion_cpu-0.1.4-cp312-cp312-win_amd64.whl
| Download URL | mnemefusion_cpu-0.1.4-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
437d3b3d4b02afd98f9f6f66e8498dc1e3e85803e5ad684657b6d93759108504
|
|
BLAKE2b-256 checksum How to use checksums |
368399fb9366b5576ea392ac183980fa096840584d62dc84dca2e4c960d1d566
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / mnemefusion_cpu-0.1.4-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | mnemefusion_cpu-0.1.4-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
a087f3b9e2d0ff39fc8545a65453b9e692d495ee64c5685510333cf01d425bd3
|
|
BLAKE2b-256 checksum How to use checksums |
828798749be29ba2522ab81857407f2eb6a86dca6bab68a7cef8e4542272766f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / mnemefusion_cpu-0.1.4-cp312-cp312-macosx_11_0_arm64.whl
| Download URL | mnemefusion_cpu-0.1.4-cp312-cp312-macosx_11_0_arm64.whl |
|---|---|
| Size | 2.9 MB |
| Tags | CPython 3.12 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
f412b12281d4d23772278d2252cc38eef9c5b87477ad64ec1126985406d74978
|
|
BLAKE2b-256 checksum How to use checksums |
78ab9b4baf1da2bd15ec1e17f88bdc037852740677914bb06a21bf3691005076
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / mnemefusion_cpu-0.1.4-cp312-cp312-macosx_10_15_x86_64.whl
| Download URL | mnemefusion_cpu-0.1.4-cp312-cp312-macosx_10_15_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.12 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
21bff6b038b03193b86f0e47ba5dcfa85a8da2b3f8ab59da8986b07e21444cdd
|
|
BLAKE2b-256 checksum How to use checksums |
6f5cdf16c5c0cf168976c64fd47d487fe0396f8826ee4ee8e3db37376465aadc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|