Skip to content

Commit f7fd110

Browse files
committed
feat(examples): Add Local RAG demo
- Add local_rag_demo example demonstrating self-managed RAG pipeline - Shows SentenceChunker, FixedSizeChunker, and LLM integration - Documents stay local, only chunks sent for embeddings - Add aiofiles dependency to agents-core for async file operations
1 parent f27073e commit f7fd110

File tree

8 files changed

+6318
-4
lines changed

8 files changed

+6318
-4
lines changed

agents-core/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ dependencies = [
2727
"numpy>=1.24.0",
2828
"mcp>=1.16.0",
2929
"colorlog>=6.10.1",
30+
"aiofiles>=24.1.0",
3031
]
3132

3233
[project.urls]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Local RAG Demo
2+
3+
Demonstrates self-managed RAG with pluggable components.
4+
5+
## What makes it "local"?
6+
7+
Unlike managed RAG (Gemini/OpenAI Vector Store), LocalRAG gives you control:
8+
9+
| Component | What happens |
10+
|-----------|--------------|
11+
| **Chunking** | Done locally by your chosen chunker |
12+
| **Embeddings** | API call returns vectors to you (text not stored remotely) |
13+
| **Vector Store** | Stored in local memory |
14+
| **Search** | Local cosine similarity (no API call) |
15+
16+
Your documents never leave your machine - only text chunks are sent to the embedding API.
17+
18+
## Components
19+
20+
- **Chunkers**: `SentenceChunker`, `FixedSizeChunker`
21+
- **Embeddings**: `OpenAIEmbeddings` (or implement your own)
22+
- **Vector Stores**: `InMemoryVectorStore` (or implement your own)
23+
24+
## Setup
25+
26+
```bash
27+
export OPENAI_API_KEY=your-key-here
28+
```
29+
30+
## Run
31+
32+
```bash
33+
cd examples/other_examples/local_rag_demo
34+
uv run python local_rag_demo.py
35+
```
36+
37+
## Demos included
38+
39+
1. **SentenceChunker** - Natural text boundaries
40+
2. **FixedSizeChunker** - Fixed size with overlap
41+
3. **LLM Integration** - Automatic context injection
42+
4. **File ingestion** - Add files directly
43+
44+
## Making it fully offline
45+
46+
To eliminate all API calls, implement a local embedding provider:
47+
48+
```python
49+
class LocalEmbeddings(EmbeddingProvider):
50+
def __init__(self):
51+
from sentence_transformers import SentenceTransformer
52+
self._model = SentenceTransformer("all-MiniLM-L6-v2")
53+
54+
@property
55+
def dimension(self) -> int:
56+
return 384
57+
58+
async def embed(self, text: str) -> list[float]:
59+
return self._model.encode(text).tolist()
60+
```
61+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Local RAG Demo
2+

0 commit comments

Comments
 (0)