Skip to main content

TF-IDF keyword retrieval memory for Autourgos agents — KeywordRetriever, KeywordMemory.

Project description

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

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

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.

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.

Links


License

MIT — see LICENSE

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

autourgos_semantic_memory-1.0.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autourgos_semantic_memory-1.0.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file autourgos_semantic_memory-1.0.0.tar.gz.

File metadata

File hashes

Hashes for autourgos_semantic_memory-1.0.0.tar.gz
Algorithm Hash digest
SHA256 985dc0bd3063526f0a51e58505a39ffab38db46c1fee45cb527c98f8a96adf91
MD5 4f39ffcfb74b9e30e2f9c326abb78de2
BLAKE2b-256 8bbbb1e39ce569f07e4dca54a754f86e7fc0b825d1627a51ffe0bcc2c893c1e9

See more details on using hashes here.

File details

Details for the file autourgos_semantic_memory-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for autourgos_semantic_memory-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a1036fb45d5f634750b1a73db1af847600114cff1468d00fa9b51e40dfe73ec
MD5 c101526919e7462ba2d4f7df48b1a055
BLAKE2b-256 94104fab4506709cd5a7d1a072a54ebf6e49769f1f3a7a23a0ef66d10ee5d037

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page