Python bindings for the EngramDB database
Project description
EngramDB Python Bindings
Python bindings for the EngramDB database.
Overview
This package provides Python bindings for the EngramDB database, allowing Python applications to leverage the specialized agent memory database system. It uses PyO3 to create efficient Rust-Python bindings with minimal overhead.
Installation
pip install engramdb-py
Usage
Basic Usage
import engramdb
# Create an in-memory database
db = engramdb.Database.in_memory()
# Create a memory node
memory = engramdb.MemoryNode([0.1, 0.2, 0.3, 0.4])
memory.set_attribute("title", "Important information")
memory.set_attribute("importance", 0.8)
# Save to database
memory_id = db.save(memory)
print(f"Saved memory with ID: {memory_id}")
# Search for similar memories
results = db.search_similar([0.15, 0.25, 0.35, 0.45], limit=5, threshold=0.7)
for memory_id, score in results:
memory = db.load(memory_id)
print(f"Found similar memory: {memory.get_attribute('title')} (score: {score:.2f})")
Persistent Storage
# Create a file-based database
db = engramdb.Database.file_based("./my_database")
Memory Connections (Graph Features)
# Create related memories
memory1 = engramdb.MemoryNode([0.1, 0.2, 0.3])
memory1.set_attribute("title", "Project Plan")
memory2 = engramdb.MemoryNode([0.2, 0.3, 0.4])
memory2.set_attribute("title", "Meeting Notes")
# Save both memories
memory1_id = db.save(memory1)
memory2_id = db.save(memory2)
# Create a connection
db.connect(
memory1_id,
memory2_id,
"related_to",
0.8
)
Thread Safety for Multi-Agent Systems
For systems with multiple agents accessing the same database concurrently:
# Create a thread-safe database
db = engramdb.ThreadSafeDatabase.in_memory()
# Operations are the same, but thread-safe
memory = engramdb.MemoryNode([0.1, 0.2, 0.3, 0.4])
memory_id = db.save(memory)
# For connection pools in shared environments
pool = engramdb.ThreadSafeDatabasePool.new("./shared_db")
db_conn = pool.get_connection()
API Reference
Database
Database.in_memory()- Create an in-memory databaseDatabase.file_based(path)- Create a file-based databaseDatabase.save(memory)- Save a memory nodeDatabase.load(id)- Load a memory node by IDDatabase.delete(id)- Delete a memory nodeDatabase.search_similar(vector, limit, threshold)- Search for similar memory nodesDatabase.connect(source_id, target_id, relationship_type, strength)- Create connection between nodes
MemoryNode
MemoryNode(embeddings)- Create a new memory nodeMemoryNode.id- Get the node IDMemoryNode.set_attribute(key, value)- Set an attributeMemoryNode.get_attribute(key)- Get an attributeMemoryNode.get_embeddings()- Get the vector embeddings
ThreadSafeDatabase
ThreadSafeDatabase.in_memory()- Create an in-memory thread-safe databaseThreadSafeDatabase.file_based(path)- Create a file-based thread-safe databaseThreadSafeDatabase.in_memory_with_hnsw()- Create database with HNSW index
ThreadSafeDatabasePool
ThreadSafeDatabasePool.new(path)- Create a database connection poolThreadSafeDatabasePool.get_connection()- Get a connection from the pool
LLM Context Generation
This package includes tools to generate XML context files for LLMs:
# Generate basic llms.txt file
python scripts/build_llms_txt.py
# Generate full context with examples
python scripts/build_llms_txt.py --full
# Convert to XML context format
python scripts/llms_txt2ctx.py llms-full-engramdb.txt --optional > llms-full-engramdb.md
Development
Building from Source
To build the package from source:
git clone https://github.com/nkkko/engramdb.git
cd engramdb/python
pip install maturin
maturin develop
Cross-Platform Building
See PUBLISHING.md for detailed instructions on building wheels for different platforms.
Running Tests
pytest tests/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
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 engramdb_py-0.1.1-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: engramdb_py-0.1.1-cp313-cp313-macosx_11_0_arm64.whl
- Upload date:
- Size: 423.7 kB
- Tags: CPython 3.13, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3411231c96666404f911fa8bb6d6f571a043939551fdec7b1c2df6ba97750d1d
|
|
| MD5 |
872b54230af5ce829212d475aea38b17
|
|
| BLAKE2b-256 |
98b34ef743ef6b08b32895f6ec44319ae1d4210fc29d7cbea6455ee408a40b6e
|