Skip to main content
Archived

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.


Install

pip install autourgos-semantic-memory

Quick Start

my_llm below is any chat-model instance, e.g. OpenAIChatModel from autourgos-openaichat (pip install autourgos-openaichat, needs OPENAI_API_KEY set). See that package's README for setup.

Classes

KeywordMemory

Dual-store memory: recent messages in a ring buffer + all messages indexed for TF-IDF retrieval.

from autourgos_semantic_memory import KeywordMemory
from autourgos_react_agent import ReactAgent
from autourgos_openaichat import OpenAIChatModel

my_llm = OpenAIChatModel(model="gpt-4o-mini")
memory = KeywordMemory(top_k=3)  # surface top 3 relevant past messages
agent  = ReactAgent(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. Default None keeps the index unbounded (unchanged prior behavior).

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.


Links


License

MIT — see LICENSE

Metadata

Release files for autourgos-semantic-memory 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for autourgos-semantic-memory 2.1.0
File Size Uploaded
autourgos_semantic_memory-2.1.0.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for autourgos-semantic-memory 2.1.0
File Interpreter ABI Platform
autourgos_semantic_memory-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / autourgos_semantic_memory-2.1.0.tar.gz

Download URL autourgos_semantic_memory-2.1.0.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c1ebbef98ba840d89711247aa779076d060118138685f95e474e6d804432f9b7
BLAKE2b-256 checksum
How to use checksums
624328560eec1ed81c6693e40a6ca2c90987c6a7374dcae87d8db530a5a10714
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12

Release files / autourgos_semantic_memory-2.1.0-py3-none-any.whl

Download URL autourgos_semantic_memory-2.1.0-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa17cd789da856b3080440b4e9cff3e5fcf9066e0b224eb09781e7a8a85d1b81
BLAKE2b-256 checksum
How to use checksums
4239ca09ce191cb9f95df4f594d1aac27702af0c55ab4ba69cddb3eea3c3eb81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.12
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page