Added API as an option to the installation, reorganized the API and fused all documentations in README.md
Browse files- README.md +288 -0
- api/README_LOLLMS.md +0 -177
- api/README_OLLAMA.md +0 -177
- api/README_OPENAI.md +0 -171
- {api β lightrag/api}/.gitignore +0 -0
- {api β lightrag/api}/lollms_lightrag_server.py +4 -1
- {api β lightrag/api}/ollama_lightrag_server.py +4 -1
- {api β lightrag/api}/openai_lightrag_server.py +4 -1
- {api β lightrag/api}/requirements.txt +0 -0
- setup.py +20 -0
README.md
CHANGED
|
@@ -1019,6 +1019,294 @@ def extract_queries(file_path):
|
|
| 1019 |
βββ test.py
|
| 1020 |
```
|
| 1021 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
| 1022 |
|
| 1023 |
## Star History
|
| 1024 |
|
|
|
|
| 1019 |
βββ test.py
|
| 1020 |
```
|
| 1021 |
|
| 1022 |
+
## Install with API Support
|
| 1023 |
+
|
| 1024 |
+
LightRAG provides optional API support through FastAPI servers that add RAG capabilities to existing LLM services. You can install LightRAG with API support in two ways:
|
| 1025 |
+
|
| 1026 |
+
### 1. Installation from PyPI
|
| 1027 |
+
|
| 1028 |
+
```bash
|
| 1029 |
+
pip install "lightrag-hku[api]"
|
| 1030 |
+
```
|
| 1031 |
+
|
| 1032 |
+
### 2. Installation from Source (Development)
|
| 1033 |
+
|
| 1034 |
+
```bash
|
| 1035 |
+
# Clone the repository
|
| 1036 |
+
git clone https://github.com/ParisNeo/lightrag.git
|
| 1037 |
+
|
| 1038 |
+
# Change to the repository directory
|
| 1039 |
+
cd lightrag
|
| 1040 |
+
|
| 1041 |
+
# Install in editable mode with API support
|
| 1042 |
+
pip install -e ".[api]"
|
| 1043 |
+
```
|
| 1044 |
+
|
| 1045 |
+
### Prerequisites
|
| 1046 |
+
|
| 1047 |
+
Before running any of the servers, ensure you have the corresponding backend service running:
|
| 1048 |
+
|
| 1049 |
+
#### For LoLLMs Server
|
| 1050 |
+
- LoLLMs must be running and accessible
|
| 1051 |
+
- Default connection: http://localhost:11434
|
| 1052 |
+
- Configure using --lollms-host if running on a different host/port
|
| 1053 |
+
|
| 1054 |
+
#### For Ollama Server
|
| 1055 |
+
- Ollama must be running and accessible
|
| 1056 |
+
- Default connection: http://localhost:11434
|
| 1057 |
+
- Configure using --ollama-host if running on a different host/port
|
| 1058 |
+
|
| 1059 |
+
#### For OpenAI Server
|
| 1060 |
+
- Requires valid OpenAI API credentials set in environment variables
|
| 1061 |
+
- OPENAI_API_KEY must be set
|
| 1062 |
+
|
| 1063 |
+
### Configuration Options
|
| 1064 |
+
|
| 1065 |
+
Each server has its own specific configuration options:
|
| 1066 |
+
|
| 1067 |
+
#### LoLLMs Server Options
|
| 1068 |
+
|
| 1069 |
+
| Parameter | Default | Description |
|
| 1070 |
+
|-----------|---------|-------------|
|
| 1071 |
+
| --host | 0.0.0.0 | RAG server host |
|
| 1072 |
+
| --port | 9621 | RAG server port |
|
| 1073 |
+
| --model | mistral-nemo:latest | LLM model name |
|
| 1074 |
+
| --embedding-model | bge-m3:latest | Embedding model name |
|
| 1075 |
+
| --lollms-host | http://localhost:11434 | LoLLMS backend URL |
|
| 1076 |
+
| --working-dir | ./rag_storage | Working directory for RAG |
|
| 1077 |
+
| --max-async | 4 | Maximum async operations |
|
| 1078 |
+
| --max-tokens | 32768 | Maximum token size |
|
| 1079 |
+
| --embedding-dim | 1024 | Embedding dimensions |
|
| 1080 |
+
| --max-embed-tokens | 8192 | Maximum embedding token size |
|
| 1081 |
+
| --input-file | ./book.txt | Initial input file |
|
| 1082 |
+
| --log-level | INFO | Logging level |
|
| 1083 |
+
|
| 1084 |
+
#### Ollama Server Options
|
| 1085 |
+
|
| 1086 |
+
| Parameter | Default | Description |
|
| 1087 |
+
|-----------|---------|-------------|
|
| 1088 |
+
| --host | 0.0.0.0 | RAG server host |
|
| 1089 |
+
| --port | 9621 | RAG server port |
|
| 1090 |
+
| --model | mistral-nemo:latest | LLM model name |
|
| 1091 |
+
| --embedding-model | bge-m3:latest | Embedding model name |
|
| 1092 |
+
| --ollama-host | http://localhost:11434 | Ollama backend URL |
|
| 1093 |
+
| --working-dir | ./rag_storage | Working directory for RAG |
|
| 1094 |
+
| --max-async | 4 | Maximum async operations |
|
| 1095 |
+
| --max-tokens | 32768 | Maximum token size |
|
| 1096 |
+
| --embedding-dim | 1024 | Embedding dimensions |
|
| 1097 |
+
| --max-embed-tokens | 8192 | Maximum embedding token size |
|
| 1098 |
+
| --input-file | ./book.txt | Initial input file |
|
| 1099 |
+
| --log-level | INFO | Logging level |
|
| 1100 |
+
|
| 1101 |
+
#### OpenAI Server Options
|
| 1102 |
+
|
| 1103 |
+
| Parameter | Default | Description |
|
| 1104 |
+
|-----------|---------|-------------|
|
| 1105 |
+
| --host | 0.0.0.0 | RAG server host |
|
| 1106 |
+
| --port | 9621 | RAG server port |
|
| 1107 |
+
| --model | gpt-4 | OpenAI model name |
|
| 1108 |
+
| --embedding-model | text-embedding-3-large | OpenAI embedding model |
|
| 1109 |
+
| --working-dir | ./rag_storage | Working directory for RAG |
|
| 1110 |
+
| --max-tokens | 32768 | Maximum token size |
|
| 1111 |
+
| --max-embed-tokens | 8192 | Maximum embedding token size |
|
| 1112 |
+
| --input-dir | ./inputs | Input directory for documents |
|
| 1113 |
+
| --log-level | INFO | Logging level |
|
| 1114 |
+
|
| 1115 |
+
### Example Usage
|
| 1116 |
+
|
| 1117 |
+
#### LoLLMs RAG Server
|
| 1118 |
+
|
| 1119 |
+
```bash
|
| 1120 |
+
# Custom configuration with specific model and working directory
|
| 1121 |
+
lollms-lightrag-server --model mistral-nemo --port 8080 --working-dir ./custom_rag
|
| 1122 |
+
|
| 1123 |
+
# Using specific models (ensure they are installed in your LoLLMs instance)
|
| 1124 |
+
lollms-lightrag-server --model mistral-nemo:latest --embedding-model bge-m3 --embedding-dim 1024
|
| 1125 |
+
```
|
| 1126 |
+
|
| 1127 |
+
#### Ollama RAG Server
|
| 1128 |
+
|
| 1129 |
+
```bash
|
| 1130 |
+
# Custom configuration with specific model and working directory
|
| 1131 |
+
ollama-lightrag-server --model mistral-nemo:latest --port 8080 --working-dir ./custom_rag
|
| 1132 |
+
|
| 1133 |
+
# Using specific models (ensure they are installed in your Ollama instance)
|
| 1134 |
+
ollama-lightrag-server --model mistral-nemo:latest --embedding-model bge-m3 --embedding-dim 1024
|
| 1135 |
+
```
|
| 1136 |
+
|
| 1137 |
+
#### OpenAI RAG Server
|
| 1138 |
+
|
| 1139 |
+
```bash
|
| 1140 |
+
# Using GPT-4 with text-embedding-3-large
|
| 1141 |
+
openai-lightrag-server --port 9624 --model gpt-4 --embedding-model text-embedding-3-large
|
| 1142 |
+
```
|
| 1143 |
+
|
| 1144 |
+
**Important Notes:**
|
| 1145 |
+
- For LoLLMs: Make sure the specified models are installed in your LoLLMs instance
|
| 1146 |
+
- For Ollama: Make sure the specified models are installed in your Ollama instance
|
| 1147 |
+
- For OpenAI: Ensure you have set up your OPENAI_API_KEY environment variable
|
| 1148 |
+
|
| 1149 |
+
For help on any server, use the --help flag:
|
| 1150 |
+
```bash
|
| 1151 |
+
lollms-lightrag-server --help
|
| 1152 |
+
ollama-lightrag-server --help
|
| 1153 |
+
openai-lightrag-server --help
|
| 1154 |
+
```
|
| 1155 |
+
|
| 1156 |
+
Note: If you don't need the API functionality, you can install the base package without API support using:
|
| 1157 |
+
```bash
|
| 1158 |
+
pip install lightrag-hku
|
| 1159 |
+
```
|
| 1160 |
+
|
| 1161 |
+
## API Endpoints
|
| 1162 |
+
|
| 1163 |
+
All servers (LoLLMs, Ollama, and OpenAI) provide the same REST API endpoints for RAG functionality.
|
| 1164 |
+
|
| 1165 |
+
### Query Endpoints
|
| 1166 |
+
|
| 1167 |
+
#### POST /query
|
| 1168 |
+
Query the RAG system with options for different search modes.
|
| 1169 |
+
|
| 1170 |
+
```bash
|
| 1171 |
+
curl -X POST "http://localhost:9621/query" \
|
| 1172 |
+
-H "Content-Type: application/json" \
|
| 1173 |
+
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 1174 |
+
```
|
| 1175 |
+
|
| 1176 |
+
#### POST /query/stream
|
| 1177 |
+
Stream responses from the RAG system.
|
| 1178 |
+
|
| 1179 |
+
```bash
|
| 1180 |
+
curl -X POST "http://localhost:9621/query/stream" \
|
| 1181 |
+
-H "Content-Type: application/json" \
|
| 1182 |
+
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 1183 |
+
```
|
| 1184 |
+
|
| 1185 |
+
### Document Management Endpoints
|
| 1186 |
+
|
| 1187 |
+
#### POST /documents/text
|
| 1188 |
+
Insert text directly into the RAG system.
|
| 1189 |
+
|
| 1190 |
+
```bash
|
| 1191 |
+
curl -X POST "http://localhost:9621/documents/text" \
|
| 1192 |
+
-H "Content-Type: application/json" \
|
| 1193 |
+
-d '{"text": "Your text content here", "description": "Optional description"}'
|
| 1194 |
+
```
|
| 1195 |
+
|
| 1196 |
+
#### POST /documents/file
|
| 1197 |
+
Upload a single file to the RAG system.
|
| 1198 |
+
|
| 1199 |
+
```bash
|
| 1200 |
+
curl -X POST "http://localhost:9621/documents/file" \
|
| 1201 |
+
-F "file=@/path/to/your/document.txt" \
|
| 1202 |
+
-F "description=Optional description"
|
| 1203 |
+
```
|
| 1204 |
+
|
| 1205 |
+
#### POST /documents/batch
|
| 1206 |
+
Upload multiple files at once.
|
| 1207 |
+
|
| 1208 |
+
```bash
|
| 1209 |
+
curl -X POST "http://localhost:9621/documents/batch" \
|
| 1210 |
+
-F "files=@/path/to/doc1.txt" \
|
| 1211 |
+
-F "files=@/path/to/doc2.txt"
|
| 1212 |
+
```
|
| 1213 |
+
|
| 1214 |
+
#### DELETE /documents
|
| 1215 |
+
Clear all documents from the RAG system.
|
| 1216 |
+
|
| 1217 |
+
```bash
|
| 1218 |
+
curl -X DELETE "http://localhost:9621/documents"
|
| 1219 |
+
```
|
| 1220 |
+
|
| 1221 |
+
### Utility Endpoints
|
| 1222 |
+
|
| 1223 |
+
#### GET /health
|
| 1224 |
+
Check server health and configuration.
|
| 1225 |
+
|
| 1226 |
+
```bash
|
| 1227 |
+
curl "http://localhost:9621/health"
|
| 1228 |
+
```
|
| 1229 |
+
|
| 1230 |
+
## Development
|
| 1231 |
+
|
| 1232 |
+
### Running in Development Mode
|
| 1233 |
+
|
| 1234 |
+
For LoLLMs:
|
| 1235 |
+
```bash
|
| 1236 |
+
uvicorn lollms_lightrag_server:app --reload --port 9621
|
| 1237 |
+
```
|
| 1238 |
+
|
| 1239 |
+
For Ollama:
|
| 1240 |
+
```bash
|
| 1241 |
+
uvicorn ollama_lightrag_server:app --reload --port 9621
|
| 1242 |
+
```
|
| 1243 |
+
|
| 1244 |
+
For OpenAI:
|
| 1245 |
+
```bash
|
| 1246 |
+
uvicorn openai_lightrag_server:app --reload --port 9621
|
| 1247 |
+
```
|
| 1248 |
+
|
| 1249 |
+
### API Documentation
|
| 1250 |
+
|
| 1251 |
+
When any server is running, visit:
|
| 1252 |
+
- Swagger UI: http://localhost:9621/docs
|
| 1253 |
+
- ReDoc: http://localhost:9621/redoc
|
| 1254 |
+
|
| 1255 |
+
### Testing API Endpoints
|
| 1256 |
+
|
| 1257 |
+
You can test the API endpoints using the provided curl commands or through the Swagger UI interface. Make sure to:
|
| 1258 |
+
1. Start the appropriate backend service (LoLLMs, Ollama, or OpenAI)
|
| 1259 |
+
2. Start the RAG server
|
| 1260 |
+
3. Upload some documents using the document management endpoints
|
| 1261 |
+
4. Query the system using the query endpoints
|
| 1262 |
+
|
| 1263 |
+
### Important Features
|
| 1264 |
+
|
| 1265 |
+
#### Automatic Document Vectorization
|
| 1266 |
+
When starting any of the servers with the `--input-dir` parameter, the system will automatically:
|
| 1267 |
+
1. Scan the specified directory for documents
|
| 1268 |
+
2. Check for existing vectorized content in the database
|
| 1269 |
+
3. Only vectorize new documents that aren't already in the database
|
| 1270 |
+
4. Make all content immediately available for RAG queries
|
| 1271 |
+
|
| 1272 |
+
This intelligent caching mechanism:
|
| 1273 |
+
- Prevents unnecessary re-vectorization of existing documents
|
| 1274 |
+
- Reduces startup time for subsequent runs
|
| 1275 |
+
- Preserves system resources
|
| 1276 |
+
- Maintains consistency across restarts
|
| 1277 |
+
|
| 1278 |
+
### Example Usage
|
| 1279 |
+
|
| 1280 |
+
#### LoLLMs RAG Server
|
| 1281 |
+
|
| 1282 |
+
```bash
|
| 1283 |
+
# Start server with automatic document vectorization
|
| 1284 |
+
# Only new documents will be vectorized, existing ones will be loaded from cache
|
| 1285 |
+
lollms-lightrag-server --input-dir ./my_documents --port 8080
|
| 1286 |
+
```
|
| 1287 |
+
|
| 1288 |
+
#### Ollama RAG Server
|
| 1289 |
+
|
| 1290 |
+
```bash
|
| 1291 |
+
# Start server with automatic document vectorization
|
| 1292 |
+
# Previously vectorized documents will be loaded from the database
|
| 1293 |
+
ollama-lightrag-server --input-dir ./my_documents --port 8080
|
| 1294 |
+
```
|
| 1295 |
+
|
| 1296 |
+
#### OpenAI RAG Server
|
| 1297 |
+
|
| 1298 |
+
```bash
|
| 1299 |
+
# Start server with automatic document vectorization
|
| 1300 |
+
# Existing documents are retrieved from cache, only new ones are processed
|
| 1301 |
+
openai-lightrag-server --input-dir ./my_documents --port 9624
|
| 1302 |
+
```
|
| 1303 |
+
|
| 1304 |
+
**Important Notes:**
|
| 1305 |
+
- The `--input-dir` parameter enables automatic document processing at startup
|
| 1306 |
+
- Documents already in the database are not re-vectorized
|
| 1307 |
+
- Only new documents in the input directory will be processed
|
| 1308 |
+
- This optimization significantly reduces startup time for subsequent runs
|
| 1309 |
+
- The working directory (`--working-dir`) stores the vectorized documents database
|
| 1310 |
|
| 1311 |
## Star History
|
| 1312 |
|
api/README_LOLLMS.md
DELETED
|
@@ -1,177 +0,0 @@
|
|
| 1 |
-
# LightRAG API Server
|
| 2 |
-
|
| 3 |
-
A powerful FastAPI-based server for managing and querying documents using LightRAG (Light Retrieval-Augmented Generation). This server provides a REST API interface for document management and intelligent querying using various LLM models through LoLLMS.
|
| 4 |
-
|
| 5 |
-
## Features
|
| 6 |
-
|
| 7 |
-
- π Multiple search modes (naive, local, global, hybrid)
|
| 8 |
-
- π‘ Streaming and non-streaming responses
|
| 9 |
-
- π Document management (insert, batch upload, clear)
|
| 10 |
-
- βοΈ Highly configurable model parameters
|
| 11 |
-
- π Support for text and file uploads
|
| 12 |
-
- π§ RESTful API with automatic documentation
|
| 13 |
-
- π Built with FastAPI for high performance
|
| 14 |
-
|
| 15 |
-
## Prerequisites
|
| 16 |
-
|
| 17 |
-
- Python 3.8+
|
| 18 |
-
- LoLLMS server running locally or remotely
|
| 19 |
-
- Required Python packages:
|
| 20 |
-
- fastapi
|
| 21 |
-
- uvicorn
|
| 22 |
-
- lightrag
|
| 23 |
-
- pydantic
|
| 24 |
-
|
| 25 |
-
## Installation
|
| 26 |
-
If you are using windows, you will need to donwload and install visual c++ build tools from [https://visualstudio.microsoft.com/visual-cpp-build-tools/ ](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
| 27 |
-
Make sure you install the VS 2022 C++ x64/x86 Build tools like from indivisual componants tab:
|
| 28 |
-

|
| 29 |
-
|
| 30 |
-
This is mandatory for builmding some modules.
|
| 31 |
-
|
| 32 |
-
1. Clone the repository:
|
| 33 |
-
```bash
|
| 34 |
-
git clone https://github.com/ParisNeo/LightRAG.git
|
| 35 |
-
cd api
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
2. Install dependencies:
|
| 39 |
-
```bash
|
| 40 |
-
pip install -r requirements.txt
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
3. Make sure LoLLMS is running and accessible.
|
| 44 |
-
|
| 45 |
-
## Configuration
|
| 46 |
-
|
| 47 |
-
The server can be configured using command-line arguments:
|
| 48 |
-
|
| 49 |
-
```bash
|
| 50 |
-
python ollama_lightollama_lightrag_server.py --help
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
Available options:
|
| 54 |
-
|
| 55 |
-
| Parameter | Default | Description |
|
| 56 |
-
|-----------|---------|-------------|
|
| 57 |
-
| --host | 0.0.0.0 | Server host |
|
| 58 |
-
| --port | 9621 | Server port |
|
| 59 |
-
| --model | mistral-nemo:latest | LLM model name |
|
| 60 |
-
| --embedding-model | bge-m3:latest | Embedding model name |
|
| 61 |
-
| --lollms-host | http://localhost:11434 | LoLLMS host URL |
|
| 62 |
-
| --working-dir | ./rag_storage | Working directory for RAG |
|
| 63 |
-
| --max-async | 4 | Maximum async operations |
|
| 64 |
-
| --max-tokens | 32768 | Maximum token size |
|
| 65 |
-
| --embedding-dim | 1024 | Embedding dimensions |
|
| 66 |
-
| --max-embed-tokens | 8192 | Maximum embedding token size |
|
| 67 |
-
| --input-file | ./book.txt | Initial input file |
|
| 68 |
-
| --log-level | INFO | Logging level |
|
| 69 |
-
|
| 70 |
-
## Quick Start
|
| 71 |
-
|
| 72 |
-
1. Basic usage with default settings:
|
| 73 |
-
```bash
|
| 74 |
-
python ollama_lightrag_server.py
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
-
2. Custom configuration:
|
| 78 |
-
```bash
|
| 79 |
-
python ollama_lightrag_server.py --model llama2:13b --port 8080 --working-dir ./custom_rag
|
| 80 |
-
```
|
| 81 |
-
|
| 82 |
-
Make sure the models are installed in your lollms instance
|
| 83 |
-
```bash
|
| 84 |
-
python ollama_lightrag_server.py --model mistral-nemo:latest --embedding-model bge-m3 --embedding-dim 1024
|
| 85 |
-
```
|
| 86 |
-
|
| 87 |
-
## API Endpoints
|
| 88 |
-
|
| 89 |
-
### Query Endpoints
|
| 90 |
-
|
| 91 |
-
#### POST /query
|
| 92 |
-
Query the RAG system with options for different search modes.
|
| 93 |
-
|
| 94 |
-
```bash
|
| 95 |
-
curl -X POST "http://localhost:9621/query" \
|
| 96 |
-
-H "Content-Type: application/json" \
|
| 97 |
-
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
#### POST /query/stream
|
| 101 |
-
Stream responses from the RAG system.
|
| 102 |
-
|
| 103 |
-
```bash
|
| 104 |
-
curl -X POST "http://localhost:9621/query/stream" \
|
| 105 |
-
-H "Content-Type: application/json" \
|
| 106 |
-
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 107 |
-
```
|
| 108 |
-
|
| 109 |
-
### Document Management Endpoints
|
| 110 |
-
|
| 111 |
-
#### POST /documents/text
|
| 112 |
-
Insert text directly into the RAG system.
|
| 113 |
-
|
| 114 |
-
```bash
|
| 115 |
-
curl -X POST "http://localhost:9621/documents/text" \
|
| 116 |
-
-H "Content-Type: application/json" \
|
| 117 |
-
-d '{"text": "Your text content here", "description": "Optional description"}'
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
#### POST /documents/file
|
| 121 |
-
Upload a single file to the RAG system.
|
| 122 |
-
|
| 123 |
-
```bash
|
| 124 |
-
curl -X POST "http://localhost:9621/documents/file" \
|
| 125 |
-
-F "file=@/path/to/your/document.txt" \
|
| 126 |
-
-F "description=Optional description"
|
| 127 |
-
```
|
| 128 |
-
|
| 129 |
-
#### POST /documents/batch
|
| 130 |
-
Upload multiple files at once.
|
| 131 |
-
|
| 132 |
-
```bash
|
| 133 |
-
curl -X POST "http://localhost:9621/documents/batch" \
|
| 134 |
-
-F "files=@/path/to/doc1.txt" \
|
| 135 |
-
-F "files=@/path/to/doc2.txt"
|
| 136 |
-
```
|
| 137 |
-
|
| 138 |
-
#### DELETE /documents
|
| 139 |
-
Clear all documents from the RAG system.
|
| 140 |
-
|
| 141 |
-
```bash
|
| 142 |
-
curl -X DELETE "http://localhost:9621/documents"
|
| 143 |
-
```
|
| 144 |
-
|
| 145 |
-
### Utility Endpoints
|
| 146 |
-
|
| 147 |
-
#### GET /health
|
| 148 |
-
Check server health and configuration.
|
| 149 |
-
|
| 150 |
-
```bash
|
| 151 |
-
curl "http://localhost:9621/health"
|
| 152 |
-
```
|
| 153 |
-
|
| 154 |
-
## Development
|
| 155 |
-
|
| 156 |
-
### Running in Development Mode
|
| 157 |
-
|
| 158 |
-
```bash
|
| 159 |
-
uvicorn ollama_lightrag_server:app --reload --port 9621
|
| 160 |
-
```
|
| 161 |
-
|
| 162 |
-
### API Documentation
|
| 163 |
-
|
| 164 |
-
When the server is running, visit:
|
| 165 |
-
- Swagger UI: http://localhost:9621/docs
|
| 166 |
-
- ReDoc: http://localhost:9621/redoc
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
## License
|
| 170 |
-
|
| 171 |
-
This project is licensed under the MIT License - see the LICENSE file for details.
|
| 172 |
-
|
| 173 |
-
## Acknowledgments
|
| 174 |
-
|
| 175 |
-
- Built with [FastAPI](https://fastapi.tiangolo.com/)
|
| 176 |
-
- Uses [LightRAG](https://github.com/HKUDS/LightRAG) for document processing
|
| 177 |
-
- Powered by [LoLLMS](https://lollms.ai/) for LLM in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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/README_OLLAMA.md
DELETED
|
@@ -1,177 +0,0 @@
|
|
| 1 |
-
# LightRAG API Server
|
| 2 |
-
|
| 3 |
-
A powerful FastAPI-based server for managing and querying documents using LightRAG (Light Retrieval-Augmented Generation). This server provides a REST API interface for document management and intelligent querying using various LLM models through Ollama.
|
| 4 |
-
|
| 5 |
-
## Features
|
| 6 |
-
|
| 7 |
-
- π Multiple search modes (naive, local, global, hybrid)
|
| 8 |
-
- π‘ Streaming and non-streaming responses
|
| 9 |
-
- π Document management (insert, batch upload, clear)
|
| 10 |
-
- βοΈ Highly configurable model parameters
|
| 11 |
-
- π Support for text and file uploads
|
| 12 |
-
- π§ RESTful API with automatic documentation
|
| 13 |
-
- π Built with FastAPI for high performance
|
| 14 |
-
|
| 15 |
-
## Prerequisites
|
| 16 |
-
|
| 17 |
-
- Python 3.8+
|
| 18 |
-
- Ollama server running locally or remotely
|
| 19 |
-
- Required Python packages:
|
| 20 |
-
- fastapi
|
| 21 |
-
- uvicorn
|
| 22 |
-
- lightrag
|
| 23 |
-
- pydantic
|
| 24 |
-
|
| 25 |
-
## Installation
|
| 26 |
-
If you are using windows, you will need to donwload and install visual c++ build tools from [https://visualstudio.microsoft.com/visual-cpp-build-tools/ ](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
| 27 |
-
Make sure you install the VS 2022 C++ x64/x86 Build tools like from indivisual componants tab:
|
| 28 |
-

|
| 29 |
-
|
| 30 |
-
This is mandatory for builmding some modules.
|
| 31 |
-
|
| 32 |
-
1. Clone the repository:
|
| 33 |
-
```bash
|
| 34 |
-
git clone https://github.com/ParisNeo/LightRAG.git
|
| 35 |
-
cd api
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
2. Install dependencies:
|
| 39 |
-
```bash
|
| 40 |
-
pip install -r requirements.txt
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
3. Make sure Ollama is running and accessible.
|
| 44 |
-
|
| 45 |
-
## Configuration
|
| 46 |
-
|
| 47 |
-
The server can be configured using command-line arguments:
|
| 48 |
-
|
| 49 |
-
```bash
|
| 50 |
-
python ollama_lightollama_lightrag_server.py --help
|
| 51 |
-
```
|
| 52 |
-
|
| 53 |
-
Available options:
|
| 54 |
-
|
| 55 |
-
| Parameter | Default | Description |
|
| 56 |
-
|-----------|---------|-------------|
|
| 57 |
-
| --host | 0.0.0.0 | Server host |
|
| 58 |
-
| --port | 9621 | Server port |
|
| 59 |
-
| --model | mistral-nemo:latest | LLM model name |
|
| 60 |
-
| --embedding-model | bge-m3:latest | Embedding model name |
|
| 61 |
-
| --ollama-host | http://localhost:11434 | Ollama host URL |
|
| 62 |
-
| --working-dir | ./rag_storage | Working directory for RAG |
|
| 63 |
-
| --max-async | 4 | Maximum async operations |
|
| 64 |
-
| --max-tokens | 32768 | Maximum token size |
|
| 65 |
-
| --embedding-dim | 1024 | Embedding dimensions |
|
| 66 |
-
| --max-embed-tokens | 8192 | Maximum embedding token size |
|
| 67 |
-
| --input-file | ./book.txt | Initial input file |
|
| 68 |
-
| --log-level | INFO | Logging level |
|
| 69 |
-
|
| 70 |
-
## Quick Start
|
| 71 |
-
|
| 72 |
-
1. Basic usage with default settings:
|
| 73 |
-
```bash
|
| 74 |
-
python ollama_lightrag_server.py
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
-
2. Custom configuration:
|
| 78 |
-
```bash
|
| 79 |
-
python ollama_lightrag_server.py --model llama2:13b --port 8080 --working-dir ./custom_rag
|
| 80 |
-
```
|
| 81 |
-
|
| 82 |
-
Make sure the models are installed in your ollama instance
|
| 83 |
-
```bash
|
| 84 |
-
python ollama_lightrag_server.py --model mistral-nemo:latest --embedding-model bge-m3 --embedding-dim 1024
|
| 85 |
-
```
|
| 86 |
-
|
| 87 |
-
## API Endpoints
|
| 88 |
-
|
| 89 |
-
### Query Endpoints
|
| 90 |
-
|
| 91 |
-
#### POST /query
|
| 92 |
-
Query the RAG system with options for different search modes.
|
| 93 |
-
|
| 94 |
-
```bash
|
| 95 |
-
curl -X POST "http://localhost:9621/query" \
|
| 96 |
-
-H "Content-Type: application/json" \
|
| 97 |
-
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
#### POST /query/stream
|
| 101 |
-
Stream responses from the RAG system.
|
| 102 |
-
|
| 103 |
-
```bash
|
| 104 |
-
curl -X POST "http://localhost:9621/query/stream" \
|
| 105 |
-
-H "Content-Type: application/json" \
|
| 106 |
-
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 107 |
-
```
|
| 108 |
-
|
| 109 |
-
### Document Management Endpoints
|
| 110 |
-
|
| 111 |
-
#### POST /documents/text
|
| 112 |
-
Insert text directly into the RAG system.
|
| 113 |
-
|
| 114 |
-
```bash
|
| 115 |
-
curl -X POST "http://localhost:9621/documents/text" \
|
| 116 |
-
-H "Content-Type: application/json" \
|
| 117 |
-
-d '{"text": "Your text content here", "description": "Optional description"}'
|
| 118 |
-
```
|
| 119 |
-
|
| 120 |
-
#### POST /documents/file
|
| 121 |
-
Upload a single file to the RAG system.
|
| 122 |
-
|
| 123 |
-
```bash
|
| 124 |
-
curl -X POST "http://localhost:9621/documents/file" \
|
| 125 |
-
-F "file=@/path/to/your/document.txt" \
|
| 126 |
-
-F "description=Optional description"
|
| 127 |
-
```
|
| 128 |
-
|
| 129 |
-
#### POST /documents/batch
|
| 130 |
-
Upload multiple files at once.
|
| 131 |
-
|
| 132 |
-
```bash
|
| 133 |
-
curl -X POST "http://localhost:9621/documents/batch" \
|
| 134 |
-
-F "files=@/path/to/doc1.txt" \
|
| 135 |
-
-F "files=@/path/to/doc2.txt"
|
| 136 |
-
```
|
| 137 |
-
|
| 138 |
-
#### DELETE /documents
|
| 139 |
-
Clear all documents from the RAG system.
|
| 140 |
-
|
| 141 |
-
```bash
|
| 142 |
-
curl -X DELETE "http://localhost:9621/documents"
|
| 143 |
-
```
|
| 144 |
-
|
| 145 |
-
### Utility Endpoints
|
| 146 |
-
|
| 147 |
-
#### GET /health
|
| 148 |
-
Check server health and configuration.
|
| 149 |
-
|
| 150 |
-
```bash
|
| 151 |
-
curl "http://localhost:9621/health"
|
| 152 |
-
```
|
| 153 |
-
|
| 154 |
-
## Development
|
| 155 |
-
|
| 156 |
-
### Running in Development Mode
|
| 157 |
-
|
| 158 |
-
```bash
|
| 159 |
-
uvicorn ollama_lightrag_server:app --reload --port 9621
|
| 160 |
-
```
|
| 161 |
-
|
| 162 |
-
### API Documentation
|
| 163 |
-
|
| 164 |
-
When the server is running, visit:
|
| 165 |
-
- Swagger UI: http://localhost:9621/docs
|
| 166 |
-
- ReDoc: http://localhost:9621/redoc
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
## License
|
| 170 |
-
|
| 171 |
-
This project is licensed under the MIT License - see the LICENSE file for details.
|
| 172 |
-
|
| 173 |
-
## Acknowledgments
|
| 174 |
-
|
| 175 |
-
- Built with [FastAPI](https://fastapi.tiangolo.com/)
|
| 176 |
-
- Uses [LightRAG](https://github.com/HKUDS/LightRAG) for document processing
|
| 177 |
-
- Powered by [Ollama](https://ollama.ai/) for LLM inference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api/README_OPENAI.md
DELETED
|
@@ -1,171 +0,0 @@
|
|
| 1 |
-
|
| 2 |
-
# LightRAG API Server
|
| 3 |
-
|
| 4 |
-
A powerful FastAPI-based server for managing and querying documents using LightRAG (Light Retrieval-Augmented Generation). This server provides a REST API interface for document management and intelligent querying using OpenAI's language models.
|
| 5 |
-
|
| 6 |
-
## Features
|
| 7 |
-
|
| 8 |
-
- π Multiple search modes (naive, local, global, hybrid)
|
| 9 |
-
- π‘ Streaming and non-streaming responses
|
| 10 |
-
- π Document management (insert, batch upload, clear)
|
| 11 |
-
- βοΈ Highly configurable model parameters
|
| 12 |
-
- π Support for text and file uploads
|
| 13 |
-
- π§ RESTful API with automatic documentation
|
| 14 |
-
- π Built with FastAPI for high performance
|
| 15 |
-
|
| 16 |
-
## Prerequisites
|
| 17 |
-
|
| 18 |
-
- Python 3.8+
|
| 19 |
-
- OpenAI API key
|
| 20 |
-
- Required Python packages:
|
| 21 |
-
- fastapi
|
| 22 |
-
- uvicorn
|
| 23 |
-
- lightrag
|
| 24 |
-
- pydantic
|
| 25 |
-
- openai
|
| 26 |
-
- nest-asyncio
|
| 27 |
-
|
| 28 |
-
## Installation
|
| 29 |
-
If you are using Windows, you will need to download and install visual c++ build tools from [https://visualstudio.microsoft.com/visual-cpp-build-tools/](https://visualstudio.microsoft.com/visual-cpp-build-tools/)
|
| 30 |
-
Make sure you install the VS 2022 C++ x64/x86 Build tools from individual components tab.
|
| 31 |
-
|
| 32 |
-
1. Clone the repository:
|
| 33 |
-
```bash
|
| 34 |
-
git clone https://github.com/ParisNeo/LightRAG.git
|
| 35 |
-
cd api
|
| 36 |
-
```
|
| 37 |
-
|
| 38 |
-
2. Install dependencies:
|
| 39 |
-
```bash
|
| 40 |
-
pip install -r requirements.txt
|
| 41 |
-
```
|
| 42 |
-
|
| 43 |
-
3. Set up your OpenAI API key:
|
| 44 |
-
```bash
|
| 45 |
-
export OPENAI_API_KEY='your-api-key-here'
|
| 46 |
-
```
|
| 47 |
-
|
| 48 |
-
## Configuration
|
| 49 |
-
|
| 50 |
-
The server can be configured using command-line arguments:
|
| 51 |
-
|
| 52 |
-
```bash
|
| 53 |
-
python openai_lightrag_server.py --help
|
| 54 |
-
```
|
| 55 |
-
|
| 56 |
-
Available options:
|
| 57 |
-
|
| 58 |
-
| Parameter | Default | Description |
|
| 59 |
-
|-----------|---------|-------------|
|
| 60 |
-
| --host | 0.0.0.0 | Server host |
|
| 61 |
-
| --port | 9621 | Server port |
|
| 62 |
-
| --model | gpt-4 | OpenAI model name |
|
| 63 |
-
| --embedding-model | text-embedding-3-large | OpenAI embedding model |
|
| 64 |
-
| --working-dir | ./rag_storage | Working directory for RAG |
|
| 65 |
-
| --max-tokens | 32768 | Maximum token size |
|
| 66 |
-
| --max-embed-tokens | 8192 | Maximum embedding token size |
|
| 67 |
-
| --input-dir | ./inputs | Input directory for documents |
|
| 68 |
-
| --log-level | INFO | Logging level |
|
| 69 |
-
|
| 70 |
-
## Quick Start
|
| 71 |
-
|
| 72 |
-
1. Basic usage with default settings:
|
| 73 |
-
```bash
|
| 74 |
-
python openai_lightrag_server.py
|
| 75 |
-
```
|
| 76 |
-
|
| 77 |
-
2. Custom configuration:
|
| 78 |
-
```bash
|
| 79 |
-
python openai_lightrag_server.py --model gpt-4 --port 8080 --working-dir ./custom_rag
|
| 80 |
-
```
|
| 81 |
-
|
| 82 |
-
## API Endpoints
|
| 83 |
-
|
| 84 |
-
### Query Endpoints
|
| 85 |
-
|
| 86 |
-
#### POST /query
|
| 87 |
-
Query the RAG system with options for different search modes.
|
| 88 |
-
|
| 89 |
-
```bash
|
| 90 |
-
curl -X POST "http://localhost:9621/query" \
|
| 91 |
-
-H "Content-Type: application/json" \
|
| 92 |
-
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 93 |
-
```
|
| 94 |
-
|
| 95 |
-
#### POST /query/stream
|
| 96 |
-
Stream responses from the RAG system.
|
| 97 |
-
|
| 98 |
-
```bash
|
| 99 |
-
curl -X POST "http://localhost:9621/query/stream" \
|
| 100 |
-
-H "Content-Type: application/json" \
|
| 101 |
-
-d '{"query": "Your question here", "mode": "hybrid"}'
|
| 102 |
-
```
|
| 103 |
-
|
| 104 |
-
### Document Management Endpoints
|
| 105 |
-
|
| 106 |
-
#### POST /documents/text
|
| 107 |
-
Insert text directly into the RAG system.
|
| 108 |
-
|
| 109 |
-
```bash
|
| 110 |
-
curl -X POST "http://localhost:9621/documents/text" \
|
| 111 |
-
-H "Content-Type: application/json" \
|
| 112 |
-
-d '{"text": "Your text content here", "description": "Optional description"}'
|
| 113 |
-
```
|
| 114 |
-
|
| 115 |
-
#### POST /documents/file
|
| 116 |
-
Upload a single file to the RAG system.
|
| 117 |
-
|
| 118 |
-
```bash
|
| 119 |
-
curl -X POST "http://localhost:9621/documents/file" \
|
| 120 |
-
-F "file=@/path/to/your/document.txt" \
|
| 121 |
-
-F "description=Optional description"
|
| 122 |
-
```
|
| 123 |
-
|
| 124 |
-
#### POST /documents/batch
|
| 125 |
-
Upload multiple files at once.
|
| 126 |
-
|
| 127 |
-
```bash
|
| 128 |
-
curl -X POST "http://localhost:9621/documents/batch" \
|
| 129 |
-
-F "files=@/path/to/doc1.txt" \
|
| 130 |
-
-F "files=@/path/to/doc2.txt"
|
| 131 |
-
```
|
| 132 |
-
|
| 133 |
-
#### DELETE /documents
|
| 134 |
-
Clear all documents from the RAG system.
|
| 135 |
-
|
| 136 |
-
```bash
|
| 137 |
-
curl -X DELETE "http://localhost:9621/documents"
|
| 138 |
-
```
|
| 139 |
-
|
| 140 |
-
### Utility Endpoints
|
| 141 |
-
|
| 142 |
-
#### GET /health
|
| 143 |
-
Check server health and configuration.
|
| 144 |
-
|
| 145 |
-
```bash
|
| 146 |
-
curl "http://localhost:9621/health"
|
| 147 |
-
```
|
| 148 |
-
|
| 149 |
-
## Development
|
| 150 |
-
|
| 151 |
-
### Running in Development Mode
|
| 152 |
-
|
| 153 |
-
```bash
|
| 154 |
-
uvicorn openai_lightrag_server:app --reload --port 9621
|
| 155 |
-
```
|
| 156 |
-
|
| 157 |
-
### API Documentation
|
| 158 |
-
|
| 159 |
-
When the server is running, visit:
|
| 160 |
-
- Swagger UI: http://localhost:9621/docs
|
| 161 |
-
- ReDoc: http://localhost:9621/redoc
|
| 162 |
-
|
| 163 |
-
## License
|
| 164 |
-
|
| 165 |
-
This project is licensed under the MIT License - see the LICENSE file for details.
|
| 166 |
-
|
| 167 |
-
## Acknowledgments
|
| 168 |
-
|
| 169 |
-
- Built with [FastAPI](https://fastapi.tiangolo.com/)
|
| 170 |
-
- Uses [LightRAG](https://github.com/HKUDS/LightRAG) for document processing
|
| 171 |
-
- Powered by [OpenAI](https://openai.com/) for language model inference
|
|
|
|
|
|
|
|
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api}/.gitignore
RENAMED
|
File without changes
|
{api β lightrag/api}/lollms_lightrag_server.py
RENAMED
|
@@ -393,9 +393,12 @@ def create_app(args):
|
|
| 393 |
return app
|
| 394 |
|
| 395 |
|
| 396 |
-
|
| 397 |
args = parse_args()
|
| 398 |
import uvicorn
|
| 399 |
|
| 400 |
app = create_app(args)
|
| 401 |
uvicorn.run(app, host=args.host, port=args.port)
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
return app
|
| 394 |
|
| 395 |
|
| 396 |
+
def main():
|
| 397 |
args = parse_args()
|
| 398 |
import uvicorn
|
| 399 |
|
| 400 |
app = create_app(args)
|
| 401 |
uvicorn.run(app, host=args.host, port=args.port)
|
| 402 |
+
|
| 403 |
+
if __name__ == "__main__":
|
| 404 |
+
main()
|
{api β lightrag/api}/ollama_lightrag_server.py
RENAMED
|
@@ -393,9 +393,12 @@ def create_app(args):
|
|
| 393 |
return app
|
| 394 |
|
| 395 |
|
| 396 |
-
|
| 397 |
args = parse_args()
|
| 398 |
import uvicorn
|
| 399 |
|
| 400 |
app = create_app(args)
|
| 401 |
uvicorn.run(app, host=args.host, port=args.port)
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
return app
|
| 394 |
|
| 395 |
|
| 396 |
+
def main():
|
| 397 |
args = parse_args()
|
| 398 |
import uvicorn
|
| 399 |
|
| 400 |
app = create_app(args)
|
| 401 |
uvicorn.run(app, host=args.host, port=args.port)
|
| 402 |
+
|
| 403 |
+
if __name__ == "__main__":
|
| 404 |
+
main()
|
{api β lightrag/api}/openai_lightrag_server.py
RENAMED
|
@@ -397,9 +397,12 @@ def create_app(args):
|
|
| 397 |
return app
|
| 398 |
|
| 399 |
|
| 400 |
-
|
| 401 |
args = parse_args()
|
| 402 |
import uvicorn
|
| 403 |
|
| 404 |
app = create_app(args)
|
| 405 |
uvicorn.run(app, host=args.host, port=args.port)
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
return app
|
| 398 |
|
| 399 |
|
| 400 |
+
def main():
|
| 401 |
args = parse_args()
|
| 402 |
import uvicorn
|
| 403 |
|
| 404 |
app = create_app(args)
|
| 405 |
uvicorn.run(app, host=args.host, port=args.port)
|
| 406 |
+
|
| 407 |
+
if __name__ == "__main__":
|
| 408 |
+
main()
|
{api β lightrag/api}/requirements.txt
RENAMED
|
File without changes
|
setup.py
CHANGED
|
@@ -52,6 +52,16 @@ def read_requirements():
|
|
| 52 |
return deps
|
| 53 |
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
metadata = retrieve_metadata()
|
| 56 |
long_description = read_long_description()
|
| 57 |
requirements = read_requirements()
|
|
@@ -85,4 +95,14 @@ setuptools.setup(
|
|
| 85 |
if metadata.get("__url__")
|
| 86 |
else "",
|
| 87 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
)
|
|
|
|
| 52 |
return deps
|
| 53 |
|
| 54 |
|
| 55 |
+
def read_api_requirements():
|
| 56 |
+
api_deps = []
|
| 57 |
+
try:
|
| 58 |
+
with open("./lightrag/api/requirements.txt") as f:
|
| 59 |
+
api_deps = [line.strip() for line in f if line.strip()]
|
| 60 |
+
except FileNotFoundError:
|
| 61 |
+
print("Warning: API requirements.txt not found.")
|
| 62 |
+
return api_deps
|
| 63 |
+
|
| 64 |
+
|
| 65 |
metadata = retrieve_metadata()
|
| 66 |
long_description = read_long_description()
|
| 67 |
requirements = read_requirements()
|
|
|
|
| 95 |
if metadata.get("__url__")
|
| 96 |
else "",
|
| 97 |
},
|
| 98 |
+
extras_require={
|
| 99 |
+
"api": read_api_requirements(), # API requirements as optional
|
| 100 |
+
},
|
| 101 |
+
entry_points={
|
| 102 |
+
"console_scripts": [
|
| 103 |
+
"lollms-lightrag-server=lightrag.api.lollms_lightrag_server:main [api]",
|
| 104 |
+
"ollama-lightrag-server=lightrag.api.ollama_lightrag_server:main [api]",
|
| 105 |
+
"openai-lightrag-server=lightrag.api.openai_lightrag_server:main [api]",
|
| 106 |
+
],
|
| 107 |
+
},
|
| 108 |
)
|