No project description provided
Project description
memonto ๐ง
memonto
(memory + ontology) adds memory to AI agents based on your custom defined ontology.
- Define your own RDF ontology with
rdflib
. memonto
automatically extracts information that maps onto that ontology into a memory graph (triple store).- Memory data can be queried directly with
SPARQL
returning a list of matching triples (subject > predicate > object). - Memories can also be contextually summarized with the addition of a vector store.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Message โ โ LLM โ โ Memory Graph โ
โ โ โ โ โ ... โ
โ {Otto von Bismarck was a โ โ โ โ โ โ
โ Prussian statesman and โ โ โ โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโ
โ diplomat who oversaw the โ โ [Otto von Bismarck] โ โโ Otto von Bismarck โโ
โ unification of Germany...} โผโโบ โ โโโโโโโโโโโฌโโโโโโโฌโโโโโโโโโโโโโโโโโ
โ โ โ is a [Person] who โ โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โผโโบ livesAtโ โpartOf โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ lives in a [Place] โ โ โ โ โ
โ Ontology โ โ โ โโโโโโโโโโโผโโโโโโโผโโโโโโโโโโโโโโโโโ
โ โผโโบ called [Prussia] โ โโ Prussia โโ German Unification โโ
โ โโโโโโโโโโโโโโโ โ โ โ โโโโฌโโโโโโฌโโโโโโโโโโฌโโโโโโฌโโโโโโโโโ
โ โ Person โ โ โ and participated in โ โ โ โ โ โ โ
โ โโโโโฌโโโโโโฌโโโโ โ โ โ โ โผ โผ โผ โผ โ
โ โ โ โ โ an [Event] called โ โ ... ... ... ... โ
โ livesAtโ โpartOf โ โ โ โโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ
โ โ โ โ โ [German Unification] โ โ
โ โโโโโโโโโโโผโโ โโโผโโโโโโโโโโ โ โ โ โโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโ
โ โ Place โ โ Event โ โ โ โ โ โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โ โ โ โ SPARQL Queries / Memory Summary โ
โ โ โ โ โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Install
pip install memonto
โ๏ธ Configure
Ephemeral Mode
Use memonto
all in memory without any data stores.
[!IMPORTANT] When in
ephemeral
mode, there can be performance issues if the memory data grows too large. This mode is recommended for smaller use cases.
Define ontology
from memonto import Memonto
from rdflib import Graph, Namespace, RDF, RDFS
g = Graph()
HIST = Namespace("history:")
g.bind("hist", HIST)
g.add((HIST.Person, RDF.type, RDFS.Class))
g.add((HIST.Event, RDF.type, RDFS.Class))
g.add((HIST.Place, RDF.type, RDFS.Class))
g.add((HIST.isFrom, RDF.type, RDF.Property))
g.add((HIST.isFrom, RDFS.domain, HIST.Person))
g.add((HIST.isFrom, RDFS.range, HIST.Place))
g.add((HIST.participatesIn, RDF.type, RDF.Property))
g.add((HIST.participatesIn, RDFS.domain, HIST.Person))
g.add((HIST.participatesIn, RDFS.range, HIST.Event))
Configure LLM
config = {
"model": {
"provider": "openai",
"config": {
"model": "gpt-4o",
"api_key": "api-key",
},
}
}
memonto = Memonto(
ontology=g,
namespaces={"hist": HIST},
ephemeral=True,
)
memonto.configure(config)
Triple Store Mode
A triple store enables the persistent storage of memory data. Currently supports Apache Jena Fuseki as a triple store. To configure a triple store, add triple_store
to the top level of your config
dictionary.
Install Apache Jena Fuseki
- Download Apache Jena Fuseki here.
- Unzip to desired folder.
tar -xzf apache-jena-fuseki-X.Y.Z.tar.gz
- Run a local server.
./fuseki-server --port=8080
Configure Triple Store
config = {
"triple_store": {
"provider": "apache_jena",
"config": {
"connection_url": "http://localhost:8080/dataset_name",
},
},
}
Triple + Vector Stores Mode
A vector store enables contextual retrieval of memory data, it must be used in conjunction with a triple store. Currently supports Chroma as a vector store. To configure a vector store, add vector_store
to the top level of your config
dictionary.
Configure Local Vector Store
config = {
"vector_store": {
"provider": "chroma",
"config": {
"mode": "remote",
"path": ".local",
},
},
}
Configure Remote Vector Store
config = {
"vector_store": {
"provider": "chroma",
"config": {
"mode": "remote",
"auth": "basic",
"host": "localhost",
"port": "8080"
"token": "bearer_token"
},
},
}
config = {
"vector_store": {
"provider": "chroma",
"config": {
"mode": "remote",
"auth": "token",
"host": "localhost",
"port": "8080"
"username": "admin"
"passport": "admin1"
},
},
}
๐งฐ Usage
RDF Namespaces
memonto
supports RDF namespaces as well. Just pass in a dictionary with the namespace's name along with its rdflib.Namespace
object.
memonto = Memonto(
ontology=g,
namespaces={"hist": HIST},
)
Memory ID
For when you want to associate an ontology and memories to an unique id
.
memonto = Memonto(
id="some_id_123",
ontology=g,
namespaces={"hist": HIST},
)
Retain
Extract the relevant information from a message that maps onto your ontology. It will only extract data that matches onto an entity in your ontology.
memonto.retain("Otto von Bismarck was a Prussian statesman and diplomat who oversaw the unification of Germany.")
Recall
Get a summary of the currently stored memories. You can provide a context
for memonto
to only summarize the memories that are relevant to that context
.
[!IMPORTANT] When in
ephemeral
mode, all memories will be returned even if acontext
is provided.
# retrieve summary of memory relevant to a context
memonto.recall("Germany could unify under Prussia or Austria.")
# retrieve summary of all stored memory
memonto.recall()
Retrieve
Get the raw memory data that can be programatically accessed. Instead of a summary, get the actual stored data as a list[dict]
that can then be manipulated in code.
[!IMPORTANT] When in
ephemeral
mode, raw queries are not supported.
# retrieve raw memory data by schema
memonto.retrieve(uri=HIST.Person)
# retrieve raw memory data by SPARQL query
memonto.retrieve(query="SELECT ?s ?p ?o WHERE {GRAPH ?g {?s ?p ?o .}}")
Forget
Forget about it.
memonto.forget()
Auto Expand Ontology
Enable memonto
to automatically expand your ontology to cover new information. If memonto
sees new information that does not fit onto your ontology, it will automatically add onto your ontology to cover that new information.
memonto = Memonto(
id="some_id_123",
ontology=g,
namespaces={"hist": HIST},
auto_expand=True,
)
๐ Async Usage
All main functionalities have an async version following this function naming pattern: def a{func_name}:
async def main():
await memonto.aretain("Some user query or message")
await memonto.arecall()
await memonto.aretrieve(uri=HIST.Person)
await memonto.aforget()
๐ฎ Current and Upcoming
LLM | Vector Store | Triple Store | |||
---|---|---|---|---|---|
OpenAI | โ | Chroma | โ | Apache Jena | โ |
Anthropic | โ | Pinecone | ๐ | ||
Meta llama | ๐ | Weaviate | ๐ |
Feedback on what to support next is always welcomed!
๐ฏ Requirements
Python 3.7 or higher.
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 Distribution
File details
Details for the file memonto-0.2.1.tar.gz
.
File metadata
- Download URL: memonto-0.2.1.tar.gz
- Upload date:
- Size: 21.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbfbd409a4d93caa2789a8e369bfe371f834ad98a8c9d06b6cde61cfdc2a39eb |
|
MD5 | eb43e825e0adf5c9c69712f4b4aeeb97 |
|
BLAKE2b-256 | 4f18f06edf6ceeac6a078073fd763d7f8765ea3330360eea6460f008228a4275 |
File details
Details for the file memonto-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: memonto-0.2.1-py3-none-any.whl
- Upload date:
- Size: 28.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3e257c574d532e4873a9617b02def512eb841494225b7f7db318969502e6108c |
|
MD5 | d5dde294169fbb959ea54681164fa78f |
|
BLAKE2b-256 | cad6cd22105265d23b6d2117c1f72228468f3414a14eb7983310765704a1a745 |