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}")
# Query the database
results = db.query()\
.with_vector([0.15, 0.25, 0.35, 0.45])\
.execute()
# Process results
for node in results:
print(f"Found memory: {node.get_attribute('title')}")
Persistent Storage
# Create a file-based database
db = engramdb.Database.file_based("./my_database")
# Initialize the database (loads existing memories)
db.initialize()
Advanced Queries
# Create attribute filters
importance_filter = engramdb.AttributeFilter.greater_than("importance", 0.7)
category_filter = engramdb.AttributeFilter.equals("category", "work")
# Create a temporal filter for recent memories
time_filter = engramdb.TemporalFilter.within_last(days=7)
# Execute combined query
results = db.query()\
.with_vector([0.1, 0.3, 0.5, 0.1])\
.with_attribute_filter(importance_filter)\
.with_attribute_filter(category_filter)\
.with_temporal_filter(time_filter)\
.with_limit(10)\
.execute()
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,
relationship_type=engramdb.RelationshipType.ASSOCIATION,
strength=0.8
)
API Reference
Database
Database.in_memory()- Create an in-memory databaseDatabase.file_based(path)- Create a file-based databaseDatabase.initialize()- Initialize the databaseDatabase.save(memory)- Save a memory nodeDatabase.load(id)- Load a memory node by IDDatabase.delete(id)- Delete a memory nodeDatabase.query()- Create a query builder
MemoryNode
MemoryNode(embeddings)- Create a new memory nodeMemoryNode.id- Get the node IDMemoryNode.embeddings- Get/set the vector embeddingsMemoryNode.set_attribute(key, value)- Set an attributeMemoryNode.get_attribute(key)- Get an attribute
QueryBuilder
QueryBuilder.with_vector(vector)- Add vector similarity searchQueryBuilder.with_attribute_filter(filter)- Add attribute filterQueryBuilder.with_temporal_filter(filter)- Add temporal filterQueryBuilder.with_limit(limit)- Set maximum resultsQueryBuilder.execute()- Execute the query
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
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.0-cp313-cp313-macosx_11_0_arm64.whl.
File metadata
- Download URL: engramdb_py-0.1.0-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 |
d4f7c928e670d6e101fdbaa21d0c6f847e237f0136c737a4a659d7a244d872fb
|
|
| MD5 |
16ba0c9a19547851609690d13cf28284
|
|
| BLAKE2b-256 |
2579e53211e75d9622de4df807b968b8bf8eebc4367d7a643a5406816ba5a274
|