agent-brain-rag 1.1.0__tar.gz → 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agent_brain_rag-1.1.0 → agent_brain_rag-2.0.0}/PKG-INFO +68 -27
- agent_brain_rag-2.0.0/README.md +194 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/__init__.py +1 -1
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/main.py +90 -26
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/routers/health.py +4 -2
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/routers/index.py +1 -1
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/routers/query.py +3 -3
- agent_brain_rag-2.0.0/agent_brain_server/config/provider_config.py +308 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/config/settings.py +12 -1
- agent_brain_rag-2.0.0/agent_brain_server/indexing/__init__.py +40 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/indexing/bm25_index.py +1 -1
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/indexing/chunking.py +1 -1
- agent_brain_rag-2.0.0/agent_brain_server/indexing/embedding.py +225 -0
- agent_brain_rag-2.0.0/agent_brain_server/indexing/graph_extractors.py +582 -0
- agent_brain_rag-2.0.0/agent_brain_server/indexing/graph_index.py +536 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/models/__init__.py +9 -0
- agent_brain_rag-2.0.0/agent_brain_server/models/graph.py +253 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/models/health.py +15 -3
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/models/query.py +14 -1
- agent_brain_rag-2.0.0/agent_brain_server/providers/__init__.py +64 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/base.py +251 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/embedding/__init__.py +23 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/embedding/cohere.py +163 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/embedding/ollama.py +150 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/embedding/openai.py +118 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/exceptions.py +95 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/factory.py +157 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/summarization/__init__.py +41 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/summarization/anthropic.py +87 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/summarization/gemini.py +96 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/summarization/grok.py +95 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/summarization/ollama.py +114 -0
- agent_brain_rag-2.0.0/agent_brain_server/providers/summarization/openai.py +87 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/services/indexing_service.py +43 -4
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/services/query_service.py +212 -4
- agent_brain_rag-2.0.0/agent_brain_server/storage/__init__.py +21 -0
- agent_brain_rag-2.0.0/agent_brain_server/storage/graph_store.py +519 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/storage/vector_store.py +36 -1
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/storage_paths.py +2 -0
- {agent_brain_rag-1.1.0 → agent_brain_rag-2.0.0}/pyproject.toml +24 -8
- agent_brain_rag-1.1.0/README.md +0 -161
- agent_brain_rag-1.1.0/doc_serve_server/indexing/__init__.py +0 -19
- agent_brain_rag-1.1.0/doc_serve_server/indexing/embedding.py +0 -274
- agent_brain_rag-1.1.0/doc_serve_server/storage/__init__.py +0 -5
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/__init__.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/routers/__init__.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/config/__init__.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/indexing/document_loader.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/locking.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/models/index.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/project_root.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/runtime.py +0 -0
- {agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/services/__init__.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: agent-brain-rag
|
|
3
|
-
Version:
|
|
4
|
-
Summary: RAG-
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Agent Brain RAG - Intelligent document indexing and semantic search server that gives AI agents long-term memory
|
|
5
5
|
License: MIT
|
|
6
|
-
Keywords: rag,semantic-search,documentation,indexing,llama-index,chromadb,ai-agent,
|
|
6
|
+
Keywords: agent-brain,rag,semantic-search,ai-memory,llm-memory,documentation,indexing,llama-index,chromadb,ai-agent,claude-code,agent-memory
|
|
7
7
|
Author: Spillwave Solutions
|
|
8
8
|
Requires-Python: >=3.10,<4.0
|
|
9
9
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -16,12 +16,19 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
16
16
|
Classifier: Programming Language :: Python :: 3.13
|
|
17
17
|
Classifier: Topic :: Software Development :: Documentation
|
|
18
18
|
Classifier: Topic :: Text Processing :: Indexing
|
|
19
|
+
Provides-Extra: graphrag
|
|
20
|
+
Provides-Extra: graphrag-all
|
|
21
|
+
Provides-Extra: graphrag-kuzu
|
|
19
22
|
Requires-Dist: anthropic (>=0.40.0,<0.41.0)
|
|
20
23
|
Requires-Dist: chromadb (>=0.5.0,<0.6.0)
|
|
21
24
|
Requires-Dist: click (>=8.1.0,<9.0.0)
|
|
25
|
+
Requires-Dist: cohere (>=5.0.0,<6.0.0)
|
|
22
26
|
Requires-Dist: fastapi (>=0.115.0,<0.116.0)
|
|
27
|
+
Requires-Dist: google-generativeai (>=0.8.0,<0.9.0)
|
|
28
|
+
Requires-Dist: langextract (>=1.0.0,<2.0.0) ; extra == "graphrag" or extra == "graphrag-all"
|
|
23
29
|
Requires-Dist: llama-index-core (>=0.14.0,<0.15.0)
|
|
24
30
|
Requires-Dist: llama-index-embeddings-openai (>=0.5.0,<0.6.0)
|
|
31
|
+
Requires-Dist: llama-index-graph-stores-kuzu (>=0.9.0,<0.10.0) ; extra == "graphrag-kuzu" or extra == "graphrag-all"
|
|
25
32
|
Requires-Dist: llama-index-llms-openai (>=0.6.12,<0.7.0)
|
|
26
33
|
Requires-Dist: llama-index-readers-file (>=0.5.0,<0.6.0)
|
|
27
34
|
Requires-Dist: llama-index-retrievers-bm25 (>=0.6.0,<0.7.0)
|
|
@@ -29,23 +36,30 @@ Requires-Dist: openai (>=1.57.0,<2.0.0)
|
|
|
29
36
|
Requires-Dist: pydantic (>=2.10.0,<3.0.0)
|
|
30
37
|
Requires-Dist: pydantic-settings (>=2.6.0,<3.0.0)
|
|
31
38
|
Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
|
|
39
|
+
Requires-Dist: pyyaml (>=6.0.0,<7.0.0)
|
|
32
40
|
Requires-Dist: rank-bm25 (>=0.2.2,<0.3.0)
|
|
33
41
|
Requires-Dist: tiktoken (>=0.8.0,<0.9.0)
|
|
34
42
|
Requires-Dist: tree-sitter-language-pack (>=0.7.3,<0.8.0)
|
|
35
43
|
Requires-Dist: uvicorn[standard] (>=0.32.0,<0.33.0)
|
|
36
|
-
Project-URL: Documentation, https://github.com/SpillwaveSolutions/
|
|
37
|
-
Project-URL: Homepage, https://github.com/SpillwaveSolutions/
|
|
38
|
-
Project-URL: Repository, https://github.com/SpillwaveSolutions/
|
|
44
|
+
Project-URL: Documentation, https://github.com/SpillwaveSolutions/agent-brain/wiki
|
|
45
|
+
Project-URL: Homepage, https://github.com/SpillwaveSolutions/agent-brain
|
|
46
|
+
Project-URL: Repository, https://github.com/SpillwaveSolutions/agent-brain
|
|
39
47
|
Description-Content-Type: text/markdown
|
|
40
48
|
|
|
41
|
-
#
|
|
49
|
+
# Agent Brain RAG Server
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
> **Agent Brain** (formerly doc-serve) is an intelligent document indexing and semantic search system designed to give AI agents long-term memory.
|
|
52
|
+
|
|
53
|
+
AI agents need persistent memory to be truly useful. Agent Brain provides the retrieval infrastructure that enables context-aware, knowledge-grounded AI interactions.
|
|
54
|
+
|
|
55
|
+
[](https://pypi.org/project/agent-brain-rag/)
|
|
56
|
+
[](https://www.python.org/downloads/)
|
|
57
|
+
[](https://opensource.org/licenses/MIT)
|
|
44
58
|
|
|
45
59
|
## Installation
|
|
46
60
|
|
|
47
61
|
```bash
|
|
48
|
-
pip install
|
|
62
|
+
pip install agent-brain-rag
|
|
49
63
|
```
|
|
50
64
|
|
|
51
65
|
## Quick Start
|
|
@@ -58,32 +72,44 @@ pip install doc-serve
|
|
|
58
72
|
|
|
59
73
|
2. Start the server:
|
|
60
74
|
```bash
|
|
61
|
-
|
|
75
|
+
agent-brain-serve
|
|
62
76
|
```
|
|
63
77
|
|
|
64
78
|
The server will start at `http://127.0.0.1:8000`.
|
|
65
79
|
|
|
80
|
+
> **Note**: The legacy command `doc-serve` is still available but deprecated. Please use `agent-brain-serve` for new installations.
|
|
81
|
+
|
|
82
|
+
## Search Capabilities
|
|
83
|
+
|
|
84
|
+
Agent Brain provides multiple search strategies to match your retrieval needs:
|
|
85
|
+
|
|
86
|
+
| Search Type | Description | Best For |
|
|
87
|
+
|-------------|-------------|----------|
|
|
88
|
+
| **Semantic Search** | Natural language queries using OpenAI embeddings (`text-embedding-3-large`) | Conceptual questions, finding related content |
|
|
89
|
+
| **Keyword Search (BM25)** | Traditional keyword matching with TF-IDF ranking | Exact matches, technical terms, code identifiers |
|
|
90
|
+
| **Hybrid Search** | Combines vector + BM25 for best of both approaches | General-purpose queries, balanced recall/precision |
|
|
91
|
+
| **GraphRAG** | Knowledge graph-based retrieval for relationship-aware queries | Understanding connections, multi-hop reasoning |
|
|
92
|
+
|
|
66
93
|
## Features
|
|
67
94
|
|
|
68
95
|
- **Document Indexing**: Load and index documents from folders (PDF, Markdown, TXT, DOCX, HTML)
|
|
69
|
-
- **
|
|
70
|
-
- **
|
|
96
|
+
- **AST-Aware Code Ingestion**: Smart parsing for Python, TypeScript, JavaScript, Java, Go, Rust, C, C++
|
|
97
|
+
- **Multi-Strategy Retrieval**: Semantic, keyword, hybrid, and graph-based search
|
|
71
98
|
- **OpenAI Embeddings**: Uses `text-embedding-3-large` for high-quality embeddings
|
|
99
|
+
- **Claude Summarization**: AI-powered code summaries for better context
|
|
72
100
|
- **Chroma Vector Store**: Persistent, thread-safe vector database
|
|
73
101
|
- **FastAPI**: Modern, high-performance REST API with OpenAPI documentation
|
|
74
102
|
|
|
75
|
-
##
|
|
76
|
-
|
|
77
|
-
### Prerequisites
|
|
103
|
+
## Prerequisites
|
|
78
104
|
|
|
79
105
|
- Python 3.10+
|
|
80
|
-
-
|
|
81
|
-
-
|
|
106
|
+
- OpenAI API key (for embeddings)
|
|
107
|
+
- Anthropic API key (for summarization)
|
|
82
108
|
|
|
83
|
-
|
|
109
|
+
## Development Installation
|
|
84
110
|
|
|
85
111
|
```bash
|
|
86
|
-
cd
|
|
112
|
+
cd agent-brain-server
|
|
87
113
|
poetry install
|
|
88
114
|
```
|
|
89
115
|
|
|
@@ -98,19 +124,18 @@ cp ../.env.example .env
|
|
|
98
124
|
|
|
99
125
|
Required environment variables:
|
|
100
126
|
- `OPENAI_API_KEY`: Your OpenAI API key for embeddings
|
|
127
|
+
- `ANTHROPIC_API_KEY`: Your Anthropic API key for summarization
|
|
101
128
|
|
|
102
129
|
### Running the Server
|
|
103
130
|
|
|
104
131
|
```bash
|
|
105
132
|
# Development mode
|
|
106
|
-
poetry run uvicorn
|
|
133
|
+
poetry run uvicorn agent_brain_server.api.main:app --reload
|
|
107
134
|
|
|
108
135
|
# Or use the entry point
|
|
109
|
-
poetry run
|
|
136
|
+
poetry run agent-brain-serve
|
|
110
137
|
```
|
|
111
138
|
|
|
112
|
-
The server will start at `http://127.0.0.1:8000`.
|
|
113
|
-
|
|
114
139
|
### API Documentation
|
|
115
140
|
|
|
116
141
|
Once running, visit:
|
|
@@ -157,7 +182,7 @@ curl -X POST http://localhost:8000/query \
|
|
|
157
182
|
## Architecture
|
|
158
183
|
|
|
159
184
|
```
|
|
160
|
-
|
|
185
|
+
agent_brain_server/
|
|
161
186
|
├── api/
|
|
162
187
|
│ ├── main.py # FastAPI application
|
|
163
188
|
│ └── routers/ # Endpoint handlers
|
|
@@ -186,16 +211,32 @@ poetry run pytest
|
|
|
186
211
|
### Code Formatting
|
|
187
212
|
|
|
188
213
|
```bash
|
|
189
|
-
poetry run black
|
|
190
|
-
poetry run ruff check
|
|
214
|
+
poetry run black agent_brain_server/
|
|
215
|
+
poetry run ruff check agent_brain_server/
|
|
191
216
|
```
|
|
192
217
|
|
|
193
218
|
### Type Checking
|
|
194
219
|
|
|
195
220
|
```bash
|
|
196
|
-
poetry run mypy
|
|
221
|
+
poetry run mypy agent_brain_server/
|
|
197
222
|
```
|
|
198
223
|
|
|
224
|
+
## Documentation
|
|
225
|
+
|
|
226
|
+
- [User Guide](https://github.com/SpillwaveSolutions/agent-brain/wiki/User-Guide) - Getting started and usage
|
|
227
|
+
- [Developer Guide](https://github.com/SpillwaveSolutions/agent-brain/wiki/Developer-Guide) - Contributing and development
|
|
228
|
+
- [API Reference](https://github.com/SpillwaveSolutions/agent-brain/wiki/API-Reference) - Full API documentation
|
|
229
|
+
|
|
230
|
+
## Release Information
|
|
231
|
+
|
|
232
|
+
- **Current Version**: See [pyproject.toml](./pyproject.toml)
|
|
233
|
+
- **Release Notes**: [GitHub Releases](https://github.com/SpillwaveSolutions/agent-brain/releases)
|
|
234
|
+
- **Changelog**: [Latest Release](https://github.com/SpillwaveSolutions/agent-brain/releases/latest)
|
|
235
|
+
|
|
236
|
+
## Related Packages
|
|
237
|
+
|
|
238
|
+
- [agent-brain-cli](https://pypi.org/project/agent-brain-cli/) - Command-line interface for Agent Brain
|
|
239
|
+
|
|
199
240
|
## License
|
|
200
241
|
|
|
201
242
|
MIT
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Agent Brain RAG Server
|
|
2
|
+
|
|
3
|
+
> **Agent Brain** (formerly doc-serve) is an intelligent document indexing and semantic search system designed to give AI agents long-term memory.
|
|
4
|
+
|
|
5
|
+
AI agents need persistent memory to be truly useful. Agent Brain provides the retrieval infrastructure that enables context-aware, knowledge-grounded AI interactions.
|
|
6
|
+
|
|
7
|
+
[](https://pypi.org/project/agent-brain-rag/)
|
|
8
|
+
[](https://www.python.org/downloads/)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install agent-brain-rag
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
1. Set environment variables:
|
|
20
|
+
```bash
|
|
21
|
+
export OPENAI_API_KEY=your-key
|
|
22
|
+
export ANTHROPIC_API_KEY=your-key
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
2. Start the server:
|
|
26
|
+
```bash
|
|
27
|
+
agent-brain-serve
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
The server will start at `http://127.0.0.1:8000`.
|
|
31
|
+
|
|
32
|
+
> **Note**: The legacy command `doc-serve` is still available but deprecated. Please use `agent-brain-serve` for new installations.
|
|
33
|
+
|
|
34
|
+
## Search Capabilities
|
|
35
|
+
|
|
36
|
+
Agent Brain provides multiple search strategies to match your retrieval needs:
|
|
37
|
+
|
|
38
|
+
| Search Type | Description | Best For |
|
|
39
|
+
|-------------|-------------|----------|
|
|
40
|
+
| **Semantic Search** | Natural language queries using OpenAI embeddings (`text-embedding-3-large`) | Conceptual questions, finding related content |
|
|
41
|
+
| **Keyword Search (BM25)** | Traditional keyword matching with TF-IDF ranking | Exact matches, technical terms, code identifiers |
|
|
42
|
+
| **Hybrid Search** | Combines vector + BM25 for best of both approaches | General-purpose queries, balanced recall/precision |
|
|
43
|
+
| **GraphRAG** | Knowledge graph-based retrieval for relationship-aware queries | Understanding connections, multi-hop reasoning |
|
|
44
|
+
|
|
45
|
+
## Features
|
|
46
|
+
|
|
47
|
+
- **Document Indexing**: Load and index documents from folders (PDF, Markdown, TXT, DOCX, HTML)
|
|
48
|
+
- **AST-Aware Code Ingestion**: Smart parsing for Python, TypeScript, JavaScript, Java, Go, Rust, C, C++
|
|
49
|
+
- **Multi-Strategy Retrieval**: Semantic, keyword, hybrid, and graph-based search
|
|
50
|
+
- **OpenAI Embeddings**: Uses `text-embedding-3-large` for high-quality embeddings
|
|
51
|
+
- **Claude Summarization**: AI-powered code summaries for better context
|
|
52
|
+
- **Chroma Vector Store**: Persistent, thread-safe vector database
|
|
53
|
+
- **FastAPI**: Modern, high-performance REST API with OpenAPI documentation
|
|
54
|
+
|
|
55
|
+
## Prerequisites
|
|
56
|
+
|
|
57
|
+
- Python 3.10+
|
|
58
|
+
- OpenAI API key (for embeddings)
|
|
59
|
+
- Anthropic API key (for summarization)
|
|
60
|
+
|
|
61
|
+
## Development Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
cd agent-brain-server
|
|
65
|
+
poetry install
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Configuration
|
|
69
|
+
|
|
70
|
+
Copy the environment template and configure:
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
cp ../.env.example .env
|
|
74
|
+
# Edit .env with your API keys
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
Required environment variables:
|
|
78
|
+
- `OPENAI_API_KEY`: Your OpenAI API key for embeddings
|
|
79
|
+
- `ANTHROPIC_API_KEY`: Your Anthropic API key for summarization
|
|
80
|
+
|
|
81
|
+
### Running the Server
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
# Development mode
|
|
85
|
+
poetry run uvicorn agent_brain_server.api.main:app --reload
|
|
86
|
+
|
|
87
|
+
# Or use the entry point
|
|
88
|
+
poetry run agent-brain-serve
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### API Documentation
|
|
92
|
+
|
|
93
|
+
Once running, visit:
|
|
94
|
+
- Swagger UI: http://127.0.0.1:8000/docs
|
|
95
|
+
- ReDoc: http://127.0.0.1:8000/redoc
|
|
96
|
+
- OpenAPI JSON: http://127.0.0.1:8000/openapi.json
|
|
97
|
+
|
|
98
|
+
## API Endpoints
|
|
99
|
+
|
|
100
|
+
### Health
|
|
101
|
+
|
|
102
|
+
- `GET /health` - Server health status
|
|
103
|
+
- `GET /health/status` - Detailed indexing status
|
|
104
|
+
|
|
105
|
+
### Indexing
|
|
106
|
+
|
|
107
|
+
- `POST /index` - Start indexing documents from a folder
|
|
108
|
+
- `POST /index/add` - Add documents to existing index
|
|
109
|
+
- `DELETE /index` - Reset the index
|
|
110
|
+
|
|
111
|
+
### Querying
|
|
112
|
+
|
|
113
|
+
- `POST /query` - Semantic search query
|
|
114
|
+
- `GET /query/count` - Get indexed document count
|
|
115
|
+
|
|
116
|
+
## Example Usage
|
|
117
|
+
|
|
118
|
+
### Index Documents
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
curl -X POST http://localhost:8000/index \
|
|
122
|
+
-H "Content-Type: application/json" \
|
|
123
|
+
-d '{"folder_path": "/path/to/docs"}'
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Query Documents
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
curl -X POST http://localhost:8000/query \
|
|
130
|
+
-H "Content-Type: application/json" \
|
|
131
|
+
-d '{"query": "How do I configure authentication?", "top_k": 5}'
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Architecture
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
agent_brain_server/
|
|
138
|
+
├── api/
|
|
139
|
+
│ ├── main.py # FastAPI application
|
|
140
|
+
│ └── routers/ # Endpoint handlers
|
|
141
|
+
├── config/
|
|
142
|
+
│ └── settings.py # Configuration management
|
|
143
|
+
├── models/ # Pydantic request/response models
|
|
144
|
+
├── indexing/
|
|
145
|
+
│ ├── document_loader.py # Document loading
|
|
146
|
+
│ ├── chunking.py # Text chunking
|
|
147
|
+
│ └── embedding.py # Embedding generation
|
|
148
|
+
├── services/
|
|
149
|
+
│ ├── indexing_service.py # Indexing orchestration
|
|
150
|
+
│ └── query_service.py # Query execution
|
|
151
|
+
└── storage/
|
|
152
|
+
└── vector_store.py # Chroma vector store
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Development
|
|
156
|
+
|
|
157
|
+
### Running Tests
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
poetry run pytest
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Code Formatting
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
poetry run black agent_brain_server/
|
|
167
|
+
poetry run ruff check agent_brain_server/
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Type Checking
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
poetry run mypy agent_brain_server/
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Documentation
|
|
177
|
+
|
|
178
|
+
- [User Guide](https://github.com/SpillwaveSolutions/agent-brain/wiki/User-Guide) - Getting started and usage
|
|
179
|
+
- [Developer Guide](https://github.com/SpillwaveSolutions/agent-brain/wiki/Developer-Guide) - Contributing and development
|
|
180
|
+
- [API Reference](https://github.com/SpillwaveSolutions/agent-brain/wiki/API-Reference) - Full API documentation
|
|
181
|
+
|
|
182
|
+
## Release Information
|
|
183
|
+
|
|
184
|
+
- **Current Version**: See [pyproject.toml](./pyproject.toml)
|
|
185
|
+
- **Release Notes**: [GitHub Releases](https://github.com/SpillwaveSolutions/agent-brain/releases)
|
|
186
|
+
- **Changelog**: [Latest Release](https://github.com/SpillwaveSolutions/agent-brain/releases/latest)
|
|
187
|
+
|
|
188
|
+
## Related Packages
|
|
189
|
+
|
|
190
|
+
- [agent-brain-cli](https://pypi.org/project/agent-brain-cli/) - Command-line interface for Agent Brain
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
{agent_brain_rag-1.1.0/doc_serve_server → agent_brain_rag-2.0.0/agent_brain_server}/api/main.py
RENAMED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
"""FastAPI application entry point.
|
|
1
|
+
"""FastAPI application entry point.
|
|
2
|
+
|
|
3
|
+
This module provides the Agent Brain RAG server, a FastAPI application
|
|
4
|
+
for document indexing and semantic search. The primary entry point is
|
|
5
|
+
`agent-brain-serve`, with `doc-serve` provided for backward compatibility.
|
|
6
|
+
"""
|
|
2
7
|
|
|
3
8
|
import logging
|
|
4
9
|
import os
|
|
5
10
|
import socket
|
|
11
|
+
import sys
|
|
12
|
+
import warnings
|
|
6
13
|
from collections.abc import AsyncIterator
|
|
7
14
|
from contextlib import asynccontextmanager
|
|
8
15
|
from pathlib import Path
|
|
@@ -13,15 +20,24 @@ import uvicorn
|
|
|
13
20
|
from fastapi import FastAPI
|
|
14
21
|
from fastapi.middleware.cors import CORSMiddleware
|
|
15
22
|
|
|
16
|
-
from
|
|
17
|
-
from
|
|
18
|
-
from
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
from
|
|
23
|
-
from
|
|
24
|
-
|
|
23
|
+
from agent_brain_server import __version__
|
|
24
|
+
from agent_brain_server.config import settings
|
|
25
|
+
from agent_brain_server.config.provider_config import (
|
|
26
|
+
load_provider_settings,
|
|
27
|
+
validate_provider_config,
|
|
28
|
+
)
|
|
29
|
+
from agent_brain_server.indexing.bm25_index import BM25IndexManager
|
|
30
|
+
from agent_brain_server.locking import (
|
|
31
|
+
acquire_lock,
|
|
32
|
+
cleanup_stale,
|
|
33
|
+
is_stale,
|
|
34
|
+
release_lock,
|
|
35
|
+
)
|
|
36
|
+
from agent_brain_server.project_root import resolve_project_root
|
|
37
|
+
from agent_brain_server.runtime import RuntimeState, delete_runtime, write_runtime
|
|
38
|
+
from agent_brain_server.services import IndexingService, QueryService
|
|
39
|
+
from agent_brain_server.storage import VectorStoreManager
|
|
40
|
+
from agent_brain_server.storage_paths import resolve_state_dir, resolve_storage_paths
|
|
25
41
|
|
|
26
42
|
from .routers import health_router, index_router, query_router
|
|
27
43
|
|
|
@@ -52,7 +68,31 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
|
52
68
|
"""
|
|
53
69
|
global _runtime_state, _state_dir
|
|
54
70
|
|
|
55
|
-
logger.info("Starting
|
|
71
|
+
logger.info("Starting Agent Brain RAG server...")
|
|
72
|
+
|
|
73
|
+
# Load and validate provider configuration
|
|
74
|
+
try:
|
|
75
|
+
provider_settings = load_provider_settings()
|
|
76
|
+
validation_errors = validate_provider_config(provider_settings)
|
|
77
|
+
|
|
78
|
+
if validation_errors:
|
|
79
|
+
for error in validation_errors:
|
|
80
|
+
logger.warning(f"Provider config warning: {error}")
|
|
81
|
+
# Log but don't fail - providers may work if keys are set later
|
|
82
|
+
# or if using Ollama which doesn't need keys
|
|
83
|
+
|
|
84
|
+
# Log active provider configuration
|
|
85
|
+
logger.info(
|
|
86
|
+
f"Embedding provider: {provider_settings.embedding.provider} "
|
|
87
|
+
f"(model: {provider_settings.embedding.model})"
|
|
88
|
+
)
|
|
89
|
+
logger.info(
|
|
90
|
+
f"Summarization provider: {provider_settings.summarization.provider} "
|
|
91
|
+
f"(model: {provider_settings.summarization.model})"
|
|
92
|
+
)
|
|
93
|
+
except Exception as e:
|
|
94
|
+
logger.error(f"Failed to load provider configuration: {e}")
|
|
95
|
+
# Continue with defaults - EmbeddingGenerator will handle provider creation
|
|
56
96
|
|
|
57
97
|
if settings.OPENAI_API_KEY:
|
|
58
98
|
os.environ["OPENAI_API_KEY"] = settings.OPENAI_API_KEY
|
|
@@ -138,7 +178,7 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
|
138
178
|
|
|
139
179
|
yield
|
|
140
180
|
|
|
141
|
-
logger.info("Shutting down
|
|
181
|
+
logger.info("Shutting down Agent Brain RAG server...")
|
|
142
182
|
|
|
143
183
|
# Cleanup for per-project mode
|
|
144
184
|
if state_dir is not None:
|
|
@@ -149,12 +189,12 @@ async def lifespan(app: FastAPI) -> AsyncIterator[None]:
|
|
|
149
189
|
|
|
150
190
|
# Create FastAPI application
|
|
151
191
|
app = FastAPI(
|
|
152
|
-
title="
|
|
192
|
+
title="Agent Brain RAG API",
|
|
153
193
|
description=(
|
|
154
194
|
"RAG-based document indexing and semantic search API. "
|
|
155
195
|
"Index documents from folders and query them using natural language."
|
|
156
196
|
),
|
|
157
|
-
version="
|
|
197
|
+
version="2.0.0",
|
|
158
198
|
lifespan=lifespan,
|
|
159
199
|
docs_url="/docs",
|
|
160
200
|
redoc_url="/redoc",
|
|
@@ -180,8 +220,8 @@ app.include_router(query_router, prefix="/query", tags=["Querying"])
|
|
|
180
220
|
async def root() -> dict[str, str]:
|
|
181
221
|
"""Root endpoint redirects to docs."""
|
|
182
222
|
return {
|
|
183
|
-
"name": "
|
|
184
|
-
"version": "
|
|
223
|
+
"name": "Agent Brain RAG API",
|
|
224
|
+
"version": "2.0.0",
|
|
185
225
|
"docs": "/docs",
|
|
186
226
|
"health": "/health",
|
|
187
227
|
}
|
|
@@ -246,7 +286,7 @@ def run(
|
|
|
246
286
|
logger.info(f"Per-project mode enabled: {_state_dir}")
|
|
247
287
|
|
|
248
288
|
uvicorn.run(
|
|
249
|
-
"
|
|
289
|
+
"agent_brain_server.api.main:app",
|
|
250
290
|
host=resolved_host,
|
|
251
291
|
port=resolved_port,
|
|
252
292
|
reload=reload if reload is not None else settings.DEBUG,
|
|
@@ -254,7 +294,7 @@ def run(
|
|
|
254
294
|
|
|
255
295
|
|
|
256
296
|
@click.command()
|
|
257
|
-
@click.version_option(version=__version__, prog_name="
|
|
297
|
+
@click.version_option(version=__version__, prog_name="agent-brain-serve")
|
|
258
298
|
@click.option(
|
|
259
299
|
"--host",
|
|
260
300
|
"-h",
|
|
@@ -292,19 +332,19 @@ def cli(
|
|
|
292
332
|
state_dir: Optional[str],
|
|
293
333
|
project_dir: Optional[str],
|
|
294
334
|
) -> None:
|
|
295
|
-
"""
|
|
335
|
+
"""Agent Brain RAG Server - Document indexing and semantic search API.
|
|
296
336
|
|
|
297
337
|
Start the FastAPI server for document indexing and querying.
|
|
298
338
|
|
|
299
339
|
\b
|
|
300
340
|
Examples:
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
341
|
+
agent-brain-serve # Start with default settings
|
|
342
|
+
agent-brain-serve --port 8080 # Start on port 8080
|
|
343
|
+
agent-brain-serve --port 0 # Auto-assign an available port
|
|
344
|
+
agent-brain-serve --host 0.0.0.0 # Bind to all interfaces
|
|
345
|
+
agent-brain-serve --reload # Enable auto-reload
|
|
346
|
+
agent-brain-serve --project-dir /my/project # Per-project mode
|
|
347
|
+
agent-brain-serve --state-dir /path/.claude/doc-serve # Explicit state dir
|
|
308
348
|
|
|
309
349
|
\b
|
|
310
350
|
Environment Variables:
|
|
@@ -328,5 +368,29 @@ def cli(
|
|
|
328
368
|
run(host=host, port=port, reload=reload, state_dir=resolved_state_dir)
|
|
329
369
|
|
|
330
370
|
|
|
371
|
+
def cli_deprecated() -> None:
|
|
372
|
+
"""Deprecated entry point for doc-serve command.
|
|
373
|
+
|
|
374
|
+
Shows a deprecation warning and then runs the main CLI.
|
|
375
|
+
"""
|
|
376
|
+
warnings.warn(
|
|
377
|
+
"\n"
|
|
378
|
+
"WARNING: 'doc-serve' is deprecated and will be removed in v2.0.\n"
|
|
379
|
+
"Please use 'agent-brain-serve' instead.\n"
|
|
380
|
+
"\n"
|
|
381
|
+
"Migration guide: docs/MIGRATION.md\n"
|
|
382
|
+
"Online: https://github.com/SpillwaveSolutions/agent-brain/blob/main/docs/MIGRATION.md\n",
|
|
383
|
+
DeprecationWarning,
|
|
384
|
+
stacklevel=1,
|
|
385
|
+
)
|
|
386
|
+
# Print to stderr for visibility since warnings may be filtered
|
|
387
|
+
print(
|
|
388
|
+
"\033[93mWARNING: 'doc-serve' is deprecated. "
|
|
389
|
+
"Use 'agent-brain-serve' instead. See docs/MIGRATION.md\033[0m",
|
|
390
|
+
file=sys.stderr,
|
|
391
|
+
)
|
|
392
|
+
cli()
|
|
393
|
+
|
|
394
|
+
|
|
331
395
|
if __name__ == "__main__":
|
|
332
396
|
cli()
|
|
@@ -5,7 +5,8 @@ from typing import Literal
|
|
|
5
5
|
|
|
6
6
|
from fastapi import APIRouter, Request
|
|
7
7
|
|
|
8
|
-
from
|
|
8
|
+
from agent_brain_server import __version__
|
|
9
|
+
from agent_brain_server.models import HealthStatus, IndexingStatus
|
|
9
10
|
|
|
10
11
|
router = APIRouter()
|
|
11
12
|
|
|
@@ -54,7 +55,7 @@ async def health_check(request: Request) -> HealthStatus:
|
|
|
54
55
|
status=status,
|
|
55
56
|
message=message,
|
|
56
57
|
timestamp=datetime.now(timezone.utc),
|
|
57
|
-
version=
|
|
58
|
+
version=__version__,
|
|
58
59
|
mode=mode,
|
|
59
60
|
instance_id=instance_id,
|
|
60
61
|
project_id=project_id,
|
|
@@ -97,4 +98,5 @@ async def indexing_status(request: Request) -> IndexingStatus:
|
|
|
97
98
|
),
|
|
98
99
|
indexed_folders=status["indexed_folders"],
|
|
99
100
|
supported_languages=status.get("supported_languages", []),
|
|
101
|
+
graph_index=status.get("graph_index"),
|
|
100
102
|
)
|
|
@@ -4,7 +4,7 @@ import logging
|
|
|
4
4
|
|
|
5
5
|
from fastapi import APIRouter, HTTPException, Request, status
|
|
6
6
|
|
|
7
|
-
from
|
|
7
|
+
from agent_brain_server.models import QueryRequest, QueryResponse
|
|
8
8
|
|
|
9
9
|
logger = logging.getLogger(__name__)
|
|
10
10
|
|
|
@@ -33,8 +33,8 @@ async def query_documents(
|
|
|
33
33
|
400: Invalid query (empty or too long)
|
|
34
34
|
503: Index not ready (indexing in progress or not initialized)
|
|
35
35
|
"""
|
|
36
|
-
from
|
|
37
|
-
from
|
|
36
|
+
from agent_brain_server.services import QueryService
|
|
37
|
+
from agent_brain_server.services.indexing_service import IndexingService
|
|
38
38
|
|
|
39
39
|
query_service: QueryService = request.app.state.query_service
|
|
40
40
|
indexing_service: IndexingService = request.app.state.indexing_service
|