Skip to content

Commit 1b65a18

Browse files
committed
Checkpoint
1 parent 508852f commit 1b65a18

File tree

11 files changed

+257
-151
lines changed

11 files changed

+257
-151
lines changed

Dockerfile

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@ FROM python:3.12-slim
22

33
WORKDIR /app
44

5-
# Install dependencies
6-
COPY requirements.txt .
7-
RUN pip install --no-cache-dir -r requirements.txt
5+
# Install system dependencies including build tools
6+
RUN apt-get update && apt-get install -y \
7+
curl \
8+
build-essential \
9+
gcc \
10+
g++ \
11+
&& rm -rf /var/lib/apt/lists/*
812

9-
# Copy application code
10-
COPY . .
13+
# Copy project files
14+
COPY pyproject.toml README.md ./
15+
COPY redis_memory_server ./redis_memory_server
1116

12-
# Set environment variables
13-
ENV PORT=8000
17+
# Install Python dependencies
18+
RUN pip install --no-cache-dir -e .
1419

15-
# Run the application
16-
CMD ["python", "main.py"]
20+
# Run the API server
21+
CMD ["python", "-m", "redis_memory_server.main"]
File renamed without changes.

README.md

Lines changed: 138 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,76 @@
11
# Redis Memory Server
22

3-
A service that provides memory management for AI applications using Redis.
3+
A service that provides memory management for AI applications using Redis. This server helps manage both short-term and long-term memory for AI conversations, with features like automatic topic extraction, entity recognition, and context summarization.
44

55
## Features
66

7-
- Short-term memory management with configurable window size
8-
- Long-term memory with semantic search capabilities
9-
- Automatic context summarization using LLMs
10-
- Support for multiple model providers (OpenAI and Anthropic)
11-
- Configurable token limits based on selected model
12-
- Topic extraction using BERTopic
13-
- Named Entity Recognition using BERT
7+
- **Short-term Memory Management**
8+
- Configurable window size for recent messages
9+
- Automatic context summarization using LLMs
10+
- Token limit management based on model capabilities
1411

15-
## Configuration
12+
- **Long-term Memory**
13+
- Semantic search capabilities
14+
- Automatic message indexing
15+
- Configurable memory retention
1616

17-
The service can be configured using environment variables:
18-
19-
- `REDIS_URL`: URL for Redis connection (default: `redis://localhost:6379`)
20-
- `LONG_TERM_MEMORY`: Enable/disable long-term memory (default: `True`)
21-
- `WINDOW_SIZE`: Maximum number of messages to keep in short-term memory (default: `20`)
22-
- `OPENAI_API_KEY`: API key for OpenAI
23-
- `ANTHROPIC_API_KEY`: API key for Anthropic
24-
- `GENERATION_MODEL`: Model to use for text generation (default: `gpt-4o-mini`)
25-
- `EMBEDDING_MODEL`: Model to use for text embeddings (default: `text-embedding-3-small`)
26-
- `PORT`: Port to run the server on (default: `8000`)
27-
- `TOPIC_MODEL`: BERTopic model to use for topic extraction (default: `MaartenGr/BERTopic_Wikipedia`)
28-
- `NER_MODEL`: BERT model to use for named entity recognition (default: `dbmdz/bert-large-cased-finetuned-conll03-english`)
29-
- `ENABLE_TOPIC_EXTRACTION`: Enable/disable topic extraction (default: `True`)
30-
- `ENABLE_NER`: Enable/disable named entity recognition (default: `True`)
17+
- **Advanced Features**
18+
- Topic extraction using BERTopic
19+
- Named Entity Recognition using BERT
20+
- Support for multiple model providers (OpenAI and Anthropic)
21+
- Namespace support for session isolation
3122

32-
## Supported Models
23+
## Get Started
3324

34-
### OpenAI Models
25+
### Docker Compose
3526

36-
- `gpt-3.5-turbo`: 4K context window
37-
- `gpt-3.5-turbo-16k`: 16K context window
38-
- `gpt-4`: 8K context window
39-
- `gpt-4-32k`: 32K context window
40-
- `gpt-4o`: 128K context window
41-
- `gpt-4o-mini`: 128K context window
27+
To start the API using Docker Compose, follow these steps:
4228

43-
### Anthropic Models
29+
1. Ensure that Docker and Docker Compose are installed on your system.
4430

45-
- `claude-3-opus-20240229`: 200K context window
46-
- `claude-3-sonnet-20240229`: 200K context window
47-
- `claude-3-haiku-20240307`: 200K context window
48-
- `claude-3-5-sonnet-20240620`: 200K context window
31+
2. Open a terminal in the project root directory (where the docker-compose.yml file is located).
4932

50-
### Topic and NER Models
33+
3. (Optional) Set up your environment variables (such as OPENAI_API_KEY and ANTHROPIC_API_KEY) either in a .env file or by modifying the docker-compose.yml as needed.
5134

52-
- Topic Extraction: Uses BERTopic with the specified model (default: Wikipedia-trained model)
53-
- Named Entity Recognition: Uses BERT model fine-tuned on CoNLL-03 dataset
35+
4. Build and start the containers by running:
36+
docker-compose up --build
5437

55-
**Note**: Embedding operations always use OpenAI models, as Anthropic does not provide embedding API.
38+
5. Once the containers are up, the API will be available at http://localhost:8000. You can also access the interactive API documentation at http://localhost:8000/docs.
5639

57-
## Installation
40+
6. To stop the containers, press Ctrl+C in the terminal and then run:
41+
docker-compose down
5842

59-
1. Clone the repository
60-
2. Install dependencies: `pip install -r requirements.txt`
61-
3. Set up environment variables (see Configuration section)
62-
4. Run the server: `python main.py`
43+
Happy coding!
6344

64-
## Usage
6545

66-
### Add Messages to Memory
46+
## API Reference
6747

68-
```
69-
POST /sessions/{session_id}/memory
70-
```
48+
### API Docs
7149

72-
Request body:
73-
```json
74-
{
75-
"messages": [
76-
{
77-
"role": "user",
78-
"content": "Hello, how are you?"
79-
}
80-
],
81-
"context": "Optional context for the conversation"
82-
}
50+
API documentation is available at: http://localhost:8000/docs.
51+
52+
### Endpoint Preview
53+
54+
#### List Sessions
55+
```http
56+
GET /sessions/
8357
```
8458

59+
Query Parameters:
60+
- `page` (int): Page number (default: 1)
61+
- `size` (int): Items per page (default: 10)
62+
- `namespace` (string, optional): Filter sessions by namespace
63+
8564
Response:
8665
```json
87-
{
88-
"status": "ok"
89-
}
66+
[
67+
"session-1",
68+
"session-2"
69+
]
9070
```
9171

92-
### Get Memory
93-
94-
```
72+
#### Get Memory
73+
```http
9574
GET /sessions/{session_id}/memory
9675
```
9776

@@ -111,40 +90,119 @@ Response:
11190
}
11291
```
11392

114-
### List Sessions
115-
116-
```
117-
GET /sessions/
93+
#### Add Messages to Memory
94+
```http
95+
POST /sessions/{session_id}/memory
11896
```
11997

120-
Response:
98+
Request Body:
12199
```json
122-
[
123-
"session-1",
124-
"session-2"
125-
]
100+
{
101+
"messages": [
102+
{
103+
"role": "user",
104+
"content": "Hello, how are you?"
105+
}
106+
],
107+
"context": "Optional context for the conversation"
108+
}
126109
```
127110

128-
### Delete Session
111+
Query Parameters:
112+
- `namespace` (string, optional): Namespace for the session
129113

114+
Response:
115+
```json
116+
{
117+
"status": "ok"
118+
}
130119
```
120+
121+
#### Delete Session
122+
```http
131123
DELETE /sessions/{session_id}/memory
132124
```
133125

126+
Query Parameters:
127+
- `namespace` (string, optional): Namespace for the session
128+
134129
Response:
135130
```json
136131
{
137132
"status": "ok"
138133
}
139134
```
140135

141-
## Development
136+
## Configuration
142137

143-
To run tests:
138+
You can configure the service using environment variables:
139+
140+
| Variable | Description | Default |
141+
|----------|-------------|---------|
142+
| `REDIS_URL` | URL for Redis connection | `redis://localhost:6379` |
143+
| `LONG_TERM_MEMORY` | Enable/disable long-term memory | `True` |
144+
| `WINDOW_SIZE` | Maximum messages in short-term memory | `20` |
145+
| `OPENAI_API_KEY` | API key for OpenAI | - |
146+
| `ANTHROPIC_API_KEY` | API key for Anthropic | - |
147+
| `GENERATION_MODEL` | Model for text generation | `gpt-4o-mini` |
148+
| `EMBEDDING_MODEL` | Model for text embeddings | `text-embedding-3-small` |
149+
| `PORT` | Server port | `8000` |
150+
| `TOPIC_MODEL` | BERTopic model for topic extraction | `MaartenGr/BERTopic_Wikipedia` |
151+
| `NER_MODEL` | BERT model for NER | `dbmdz/bert-large-cased-finetuned-conll03-english` |
152+
| `ENABLE_TOPIC_EXTRACTION` | Enable/disable topic extraction | `True` |
153+
| `ENABLE_NER` | Enable/disable named entity recognition | `True` |
154+
155+
## Supported Models
144156

157+
### Large Language Models
158+
159+
Redis Memory Server supports using OpenAI and Anthropic models for generation, and OpenAI models for embeddings.
160+
161+
### Topic and NER Models
162+
- **Topic Extraction**: BERTopic with Wikipedia-trained model
163+
- **Named Entity Recognition**: BERT model fine-tuned on CoNLL-03 dataset
164+
165+
> **Note**: Embedding operations use OpenAI models exclusively, as Anthropic does not provide an embedding API.
166+
167+
## Installation
168+
169+
1. Clone the repository:
170+
```bash
171+
git clone https://github.com/yourusername/redis-memory-server.git
172+
cd redis-memory-server
145173
```
174+
175+
2. Install dependencies:
176+
```bash
177+
pip install -e ".[dev]"
178+
```
179+
180+
3. Set up environment variables (see Configuration section)
181+
182+
4. Run the server:
183+
```bash
184+
python -m redis_memory_server
185+
```
186+
187+
## Development
188+
189+
### Running Tests
190+
```bash
146191
python -m pytest
147192
```
148193

194+
### Contributing
195+
1. Fork the repository
196+
2. Create a feature branch
197+
3. Commit your changes
198+
4. Push to the branch
199+
5. Create a Pull Request
200+
149201
## License
150-
TBD
202+
This project derives from original work from the Motorhead project:
203+
https://github.com/getmetal/motorhead/
204+
205+
The original code is licensed under the Apache License 2.0:
206+
https://www.apache.org/licenses/LICENSE-2.0
207+
208+
Modifications made by Redis, Inc. are also licensed under the Apache License 2.0.

docker-compose.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
services:
2+
api:
3+
build:
4+
context: .
5+
dockerfile: Dockerfile
6+
ports:
7+
- "8000:8000"
8+
environment:
9+
- REDIS_URL=redis://redis:6379
10+
- PORT=8000
11+
# Add your API keys here or use a .env file
12+
- OPENAI_API_KEY=${OPENAI_API_KEY}
13+
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
14+
# Optional configurations with defaults
15+
- LONG_TERM_MEMORY=True
16+
- WINDOW_SIZE=20
17+
- GENERATION_MODEL=gpt-4o-mini
18+
- EMBEDDING_MODEL=text-embedding-3-small
19+
- ENABLE_TOPIC_EXTRACTION=True
20+
- ENABLE_NER=True
21+
depends_on:
22+
- redis
23+
volumes:
24+
- ./redis_memory_server:/app/redis_memory_server
25+
healthcheck:
26+
test: [ "CMD", "curl", "-f", "http://localhost:8000/health" ]
27+
interval: 30s
28+
timeout: 10s
29+
retries: 3
30+
31+
redis:
32+
image: redis/redis-stack:latest
33+
ports:
34+
- "16379:6379" # Redis port
35+
- "18001:8001" # RedisInsight port
36+
volumes:
37+
- redis_data:/data
38+
command: redis-stack-server --save 60 1 --loglevel warning
39+
healthcheck:
40+
test: [ "CMD", "redis-cli", "ping" ]
41+
interval: 30s
42+
timeout: 10s
43+
retries: 3
44+
45+
volumes:
46+
redis_data:

0 commit comments

Comments
 (0)