Skip to content

Commit 8fe0fcd

Browse files
committed
Update README with filter options README.md
1 parent 6dd02f6 commit 8fe0fcd

File tree

2 files changed

+90
-5
lines changed

2 files changed

+90
-5
lines changed

README.md

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ A Redis-powered memory server built for AI agents and applications. It manages b
77
- **Short-Term Memory**
88
- Storage for messages, token count, context, and metadata for a session
99
- Automatically and recursively summarizes conversations
10-
- Token limit management based on specific model capabilities
10+
- Client model-aware token limit management (adapts to the context window of the client's LLM)
11+
- Supports all major OpenAI and Anthropic models
1112

1213
- **Long-Term Memory**
1314
- Storage for long-term memories across sessions
14-
- Semantic search to retrieve memories, with filters such as topic, entity, etc.
15+
- Semantic search to retrieve memories with advanced filtering system
16+
- Filter by session, namespace, topics, entities, timestamps, and more
17+
- Supports both exact match and semantic similarity search
1518
- Automatic topic modeling for stored memories with BERTopic
1619
- Automatic Entity Recognition using BERT
1720

1821
- **Other Features**
19-
- Support for OpenAI and Anthropic model providers
2022
- Namespace support for session and long-term memory isolation
2123
- Both a REST interface and MCP server
2224

@@ -56,6 +58,11 @@ The following endpoints are available:
5658
- **GET /sessions/{session_id}/memory**
5759
Retrieves conversation memory for a session, including messages and
5860
summarized older messages.
61+
_Query Parameters:_
62+
- `namespace` (string, optional): The namespace to use for the session
63+
- `window_size` (int, optional): Number of messages to include in the response (default from config)
64+
- `model_name` (string, optional): The client's LLM model name to determine appropriate context window size
65+
- `context_window_max` (int, optional): Direct specification of max context window tokens (overrides model_name)
5966

6067
- **POST /sessions/{session_id}/memory**
6168
Adds messages (and optional context) to a session's memory.
@@ -81,6 +88,40 @@ The following endpoints are available:
8188
}
8289
```
8390

91+
- **POST /long-term-memory/search**
92+
Performs semantic search on long-term memories with advanced filtering options.
93+
_Request Body Example:_
94+
```json
95+
{
96+
"text": "Search query text",
97+
"limit": 10,
98+
"offset": 0,
99+
"session_id": {"eq": "session-123"},
100+
"namespace": {"eq": "default"},
101+
"topics": {"any": ["AI", "Machine Learning"]},
102+
"entities": {"all": ["OpenAI", "Claude"]},
103+
"created_at": {"gte": 1672527600, "lte": 1704063599},
104+
"last_accessed": {"gt": 1704063600},
105+
"user_id": {"eq": "user-456"}
106+
}
107+
```
108+
109+
_Filter options:_
110+
- Tag filters (session_id, namespace, topics, entities, user_id):
111+
- `eq`: Equals this value
112+
- `ne`: Not equals this value
113+
- `any`: Contains any of these values
114+
- `all`: Contains all of these values
115+
116+
- Numeric filters (created_at, last_accessed):
117+
- `gt`: Greater than
118+
- `lt`: Less than
119+
- `gte`: Greater than or equal
120+
- `lte`: Less than or equal
121+
- `eq`: Equals
122+
- `ne`: Not equals
123+
- `between`: Between two values
124+
84125
## MCP Server Interface
85126
Agent Memory Server offers an MCP (Model Context Protocol) server interface powered by FastMCP, providing tool-based long-term memory management:
86127

agent_memory_server/api.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
from typing import Literal
2+
13
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
24

35
from agent_memory_server import long_term_memory, messages
46
from agent_memory_server.config import settings
7+
from agent_memory_server.llms import get_model_config
58
from agent_memory_server.logging import get_logger
69
from agent_memory_server.models import (
710
AckResponse,
@@ -18,6 +21,32 @@
1821

1922
logger = get_logger(__name__)
2023

24+
ModelNameLiteral = Literal[
25+
"gpt-3.5-turbo",
26+
"gpt-3.5-turbo-16k",
27+
"gpt-4",
28+
"gpt-4-32k",
29+
"gpt-4o",
30+
"gpt-4o-mini",
31+
"o1",
32+
"o1-mini",
33+
"o3-mini",
34+
"text-embedding-ada-002",
35+
"text-embedding-3-small",
36+
"text-embedding-3-large",
37+
"claude-3-opus-20240229",
38+
"claude-3-sonnet-20240229",
39+
"claude-3-haiku-20240307",
40+
"claude-3-5-sonnet-20240620",
41+
"claude-3-7-sonnet-20250219",
42+
"claude-3-5-sonnet-20241022",
43+
"claude-3-5-haiku-20241022",
44+
"claude-3-7-sonnet-latest",
45+
"claude-3-5-sonnet-latest",
46+
"claude-3-5-haiku-latest",
47+
"claude-3-opus-latest",
48+
]
49+
2150
router = APIRouter()
2251

2352

@@ -54,6 +83,8 @@ async def get_session_memory(
5483
session_id: str,
5584
namespace: str | None = None,
5685
window_size: int = settings.window_size,
86+
model_name: ModelNameLiteral | None = None,
87+
context_window_max: int | None = None,
5788
):
5889
"""
5990
Get memory for a session.
@@ -62,18 +93,31 @@ async def get_session_memory(
6293
6394
Args:
6495
session_id: The session ID
65-
window_size: The number of messages to include in the response
6696
namespace: The namespace to use for the session
97+
window_size: The number of messages to include in the response
98+
model_name: The client's LLM model name (will determine context window size if provided)
99+
context_window_max: Direct specification of the context window max tokens (overrides model_name)
67100
68101
Returns:
69102
Conversation history and context
70103
"""
71104
redis = get_redis_conn()
72105

106+
# If context_window_max is explicitly provided, use that
107+
if context_window_max is not None:
108+
effective_window_size = min(window_size, context_window_max)
109+
# If model_name is provided, get its max_tokens from our config
110+
elif model_name is not None:
111+
model_config = get_model_config(model_name)
112+
effective_window_size = min(window_size, model_config.max_tokens)
113+
# Otherwise use the default window_size
114+
else:
115+
effective_window_size = window_size
116+
73117
session = await messages.get_session_memory(
74118
redis=redis,
75119
session_id=session_id,
76-
window_size=window_size,
120+
window_size=effective_window_size,
77121
namespace=namespace,
78122
)
79123
if not session:

0 commit comments

Comments
 (0)