This project has been archived by its maintainers, and is no longer receiving any updates.
autourgos-semantic-memory
TF-IDF keyword retrieval memory for Autourgos agents. Combines a short-term message buffer with a TF-IDF keyword index — when the agent asks for context, relevant past messages are retrieved by keyword similarity and prepended, even if they fell outside the short-term window. Zero external dependencies; no embeddings, no vector database required.
from autourgos_semantic_memory import KeywordMemory
from autourgos_agent import Agent
from autourgos_openaichat import OpenAIChatModel
my_llm = OpenAIChatModel(model="gpt-4o-mini")
memory = KeywordMemory(top_k=3)
agent = Agent(llm=my_llm, memory=memory)
Features
KeywordMemory— dual-store: recent messages in a ring buffer + all messages indexed for TF-IDF retrievalKeywordRetriever— standalone TF-IDF retriever, usable on its own or plugged intoKeywordMemory- Zero external dependencies — cosine similarity over TF-IDF weights, computed at query time
- Bounded index — optional
max_documentsFIFO eviction keeps retrieval fast on long-running agents
Table of Contents
Install
pip install autourgos-semantic-memory
Classes
KeywordMemory
from autourgos_semantic_memory import KeywordMemory
from autourgos_agent import Agent
from autourgos_openaichat import OpenAIChatModel
my_llm = OpenAIChatModel(model="gpt-4o-mini")
memory = KeywordMemory(top_k=3) # surface top 3 relevant past messages
agent = Agent(llm=my_llm, memory=memory)
agent.invoke("The server is running on port 8080")
agent.invoke("The database password is hunter2")
# ... many more messages ...
agent.invoke("What port is the server on?")
# → retrieves the port message from the keyword index even if it left the buffer
KeywordRetriever
Standalone TF-IDF retriever. Plug it into KeywordMemory or use directly with your own memory:
from autourgos_semantic_memory import KeywordRetriever
from autourgos_memory import Document
retriever = KeywordRetriever()
retriever.add_document(Document(content="Paris is the capital of France.", source="wiki"))
retriever.add_document(Document(content="Berlin is the capital of Germany.", source="wiki"))
results = retriever.retrieve("What is the capital of France?", top_k=1)
print(results[0].content)
# → "Paris is the capital of France."
Custom Short-Term Store
from autourgos_semantic_memory import KeywordMemory
from autourgos_local_memory import SQLiteMemory
# Use SQLite as the short-term buffer (survives restarts)
memory = KeywordMemory(
short_term=SQLiteMemory(db_path="./data/agent.db"),
top_k=5,
)
Parameters
KeywordMemory
| Parameter | Type | Default | Description |
|---|---|---|---|
short_term |
BaseMemory | RuntimeShortTermMemory(10) |
Short-term buffer shown in full. |
retriever |
BaseRetriever | KeywordRetriever() |
Retriever for past context. |
top_k |
int | 3 |
Max relevant past messages to surface. |
max_documents |
Optional[int] | None |
Max documents kept in the TF-IDF index. When set, the oldest document is dropped (FIFO) once the count would exceed this. None keeps the index unbounded. |
KeywordRetriever
| Parameter | Type | Default | Description |
|---|---|---|---|
max_documents |
Optional[int] | None |
Same FIFO eviction behavior as above, for standalone use. |
How TF-IDF Works Here
- Every message is tokenized (lowercase alphanumeric) and indexed.
- IDF weights are computed at query time — so scores stay accurate as more messages are added.
- Cosine similarity ranks results. Only messages with score > 0 are returned.
- Back-compat aliases:
SimpleSemanticRetriever = KeywordRetriever,HierarchicalSemanticMemory = KeywordMemory.
Cost note: retrieve() recomputes TF-IDF weights across the whole corpus on each call where the index
changed since the last query. This is fine for small-to-medium message stores, but the per-query cost grows
with corpus size. If you expect a long-running agent to accumulate many thousands of documents, set
max_documents to cap the index size and keep retrieval fast.
License
Apache License 2.0, Copyright (c) 2026 Jitin Kumar Sengar
Metadata
Release files for autourgos-semantic-memory 2.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 | |
|---|---|---|---|
| autourgos_semantic_memory-2.1.4.tar.gz | 18.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autourgos_semantic_memory-2.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.0 kB
Release files / autourgos_semantic_memory-2.1.4.tar.gz
| Download URL | autourgos_semantic_memory-2.1.4.tar.gz |
|---|---|
| Size | 18.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
102f1a5a757a2c78ca8456bed4ec749a1560ae235e9da1d53e228bce6084f6b9
|
|
BLAKE2b-256 checksum How to use checksums |
ea66e58e100a29ea2eaf99458ff70481dfce1be6a8e3c142a91869fc1b57ba76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|
Release files / autourgos_semantic_memory-2.1.4-py3-none-any.whl
| Download URL | autourgos_semantic_memory-2.1.4-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fede5310b53dd3f6bfa713a91c2eb9ff680cbedf394cbe22dca67ffca25429ec
|
|
BLAKE2b-256 checksum How to use checksums |
e806c1b2196d831fe76d4100a4a817266341b72813c8699390df14b14fefdf61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.9
|