Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

autourgos-semantic-memory

Framework: Autourgos Python License: Apache 2.0 Author Contributor Contributor

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 retrieval
  • KeywordRetriever — standalone TF-IDF retriever, usable on its own or plugged into KeywordMemory
  • Zero external dependencies — cosine similarity over TF-IDF weights, computed at query time
  • Bounded index — optional max_documents FIFO 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.2

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.2
File Size Uploaded
autourgos_semantic_memory-2.1.2.tar.gz 18.5 kB Details

Built distribution (wheel)

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

Total release size: 34.0 kB

Release files / autourgos_semantic_memory-2.1.2.tar.gz

Download URL autourgos_semantic_memory-2.1.2.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
22f8b27842877265064bf3387e1d7c4af51e047bdd80dd6a58be99c728ccc709
BLAKE2b-256 checksum
How to use checksums
b564f7b3ecb2addfcab45c256bed3104a9411c49e74295e1066a42f8efe5deb8
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.2-py3-none-any.whl

Download URL autourgos_semantic_memory-2.1.2-py3-none-any.whl
Size 15.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6746fd226c6863b786ef89e8cf98c7d3f85230d8a132307bacb1359e44394f08
BLAKE2b-256 checksum
How to use checksums
3587c81981942b587ab878cf0daf815bbfadfec79964d02389f13917079de1d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.9
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