yangdx commited on
Commit
39b6e79
·
1 Parent(s): 3deffe0

update README.md and .env.example

Browse files
Files changed (2) hide show
  1. .env.example +45 -50
  2. lightrag/api/README.md +149 -158
.env.example CHANGED
@@ -16,70 +16,65 @@
16
  # WORKING_DIR=<absolute_path_for_working_dir>
17
  # INPUT_DIR=<absolute_path_for_doc_input_dir>
18
 
19
- ### Logging level
20
- LOG_LEVEL=INFO
21
- VERBOSE=False
22
-
23
- ### Optional Timeout
24
- TIMEOUT=300
25
-
26
- # Ollama Emulating Model Tag
27
  # OLLAMA_EMULATING_MODEL_TAG=latest
28
 
29
- ### RAG Configuration
30
- MAX_ASYNC=4
31
- EMBEDDING_DIM=1024
32
- MAX_EMBED_TOKENS=8192
33
- ### Settings relative to query
34
- HISTORY_TURNS=3
35
- COSINE_THRESHOLD=0.2
36
- TOP_K=60
37
- MAX_TOKEN_TEXT_CHUNK=4000
38
- MAX_TOKEN_RELATION_DESC=4000
39
- MAX_TOKEN_ENTITY_DESC=4000
40
- ### Settings relative to indexing
41
- CHUNK_SIZE=1200
42
- CHUNK_OVERLAP_SIZE=100
43
- MAX_TOKENS=32768
44
- MAX_TOKEN_SUMMARY=500
45
- SUMMARY_LANGUAGE=English
46
-
47
- ### LLM Configuration (Use valid host. For local services, you can use host.docker.internal)
 
 
 
 
 
 
 
 
 
48
  ### Ollama example
49
  LLM_BINDING=ollama
50
- LLM_BINDING_HOST=http://host.docker.internal:11434
51
- LLM_MODEL=mistral-nemo:latest
52
-
53
  ### OpenAI alike example
54
  # LLM_BINDING=openai
55
- # LLM_MODEL=deepseek-chat
56
- # LLM_BINDING_HOST=https://api.deepseek.com
57
- # LLM_BINDING_API_KEY=your_api_key
58
-
59
- ### for OpenAI LLM (LLM_BINDING_API_KEY take priority)
60
- # OPENAI_API_KEY=your_api_key
61
-
62
- ### Lollms example
63
  # LLM_BINDING=lollms
64
- # LLM_BINDING_HOST=http://host.docker.internal:9600
65
- # LLM_MODEL=mistral-nemo:latest
66
 
67
-
68
- ### Embedding Configuration (Use valid host. For local services, you can use host.docker.internal)
69
- # Ollama example
70
- EMBEDDING_BINDING=ollama
71
- EMBEDDING_BINDING_HOST=http://host.docker.internal:11434
72
  EMBEDDING_MODEL=bge-m3:latest
73
-
 
 
 
 
 
 
 
74
  ### Lollms example
75
  # EMBEDDING_BINDING=lollms
76
- # EMBEDDING_BINDING_HOST=http://host.docker.internal:9600
77
- # EMBEDDING_MODEL=bge-m3:latest
78
 
79
  ### Optional for Azure (LLM_BINDING_HOST, LLM_BINDING_API_KEY take priority)
80
  # AZURE_OPENAI_API_VERSION=2024-08-01-preview
81
  # AZURE_OPENAI_DEPLOYMENT=gpt-4o
82
- # AZURE_OPENAI_API_KEY=myapikey
83
  # AZURE_OPENAI_ENDPOINT=https://myendpoint.openai.azure.com
84
 
85
  # AZURE_EMBEDDING_DEPLOYMENT=text-embedding-3-large
@@ -138,4 +133,4 @@ MONGODB_GRAPH=false # deprecated (keep for backward compatibility)
138
 
139
  ### Qdrant
140
  QDRANT_URL=http://localhost:16333
141
- QDRANT_API_KEY=your-api-key # 可选
 
16
  # WORKING_DIR=<absolute_path_for_working_dir>
17
  # INPUT_DIR=<absolute_path_for_doc_input_dir>
18
 
19
+ ### Ollama Emulating Model Tag
 
 
 
 
 
 
 
20
  # OLLAMA_EMULATING_MODEL_TAG=latest
21
 
22
+ ### Logging level
23
+ # LOG_LEVEL=INFO
24
+ # VERBOSE=False
25
+
26
+ ### Max async calls for LLM
27
+ # MAX_ASYNC=4
28
+ ### Optional Timeout for LLM
29
+ # TIMEOUT=None # Time out in seconds, None for infinite timeout
30
+
31
+ ### Settings for RAG query
32
+ # HISTORY_TURNS=3
33
+ # COSINE_THRESHOLD=0.2
34
+ # TOP_K=60
35
+ # MAX_TOKEN_TEXT_CHUNK=4000
36
+ # MAX_TOKEN_RELATION_DESC=4000
37
+ # MAX_TOKEN_ENTITY_DESC=4000
38
+
39
+ ### Settings for document indexing
40
+ # CHUNK_SIZE=1200
41
+ # CHUNK_OVERLAP_SIZE=100
42
+ # MAX_TOKENS=32768 # Max tokens send to LLM for summarization
43
+ # MAX_TOKEN_SUMMARY=500 # Max tokens for entity or relations summary
44
+ # SUMMARY_LANGUAGE=English
45
+ # MAX_EMBED_TOKENS=8192
46
+
47
+ ### LLM Configuration (Use valid host. For local services installed with docker, you can use host.docker.internal)
48
+ LLM_MODEL=mistral-nemo:latest
49
+ LLM_BINDING_API_KEY=your_api_key
50
  ### Ollama example
51
  LLM_BINDING=ollama
52
+ LLM_BINDING_HOST=http://localhost:11434
 
 
53
  ### OpenAI alike example
54
  # LLM_BINDING=openai
55
+ # LLM_BINDING_HOST=https://api.openai.com/v1
56
+ ### lollms example
 
 
 
 
 
 
57
  # LLM_BINDING=lollms
58
+ # LLM_BINDING_HOST=http://localhost:9600
 
59
 
60
+ ### Embedding Configuration (Use valid host. For local services installed with docker, you can use host.docker.internal)
 
 
 
 
61
  EMBEDDING_MODEL=bge-m3:latest
62
+ EMBEDDING_DIM=1024
63
+ # EMBEDDING_BINDING_API_KEY=your_api_key
64
+ ### ollama example
65
+ EMBEDDING_BINDING=ollama
66
+ EMBEDDING_BINDING_HOST=http://localhost:11434
67
+ ### OpenAI alike example
68
+ # EMBEDDING_BINDING=openai
69
+ # LLM_BINDING_HOST=https://api.openai.com/v1
70
  ### Lollms example
71
  # EMBEDDING_BINDING=lollms
72
+ # EMBEDDING_BINDING_HOST=http://localhost:9600
 
73
 
74
  ### Optional for Azure (LLM_BINDING_HOST, LLM_BINDING_API_KEY take priority)
75
  # AZURE_OPENAI_API_VERSION=2024-08-01-preview
76
  # AZURE_OPENAI_DEPLOYMENT=gpt-4o
77
+ # AZURE_OPENAI_API_KEY=your_api_key
78
  # AZURE_OPENAI_ENDPOINT=https://myendpoint.openai.azure.com
79
 
80
  # AZURE_EMBEDDING_DEPLOYMENT=text-embedding-3-large
 
133
 
134
  ### Qdrant
135
  QDRANT_URL=http://localhost:16333
136
+ # QDRANT_API_KEY=your-api-key
lightrag/api/README.md CHANGED
@@ -1,14 +1,14 @@
1
- ## Install with API Support
2
 
3
- 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:
4
 
5
- ### 1. Installation from PyPI
6
 
7
  ```bash
8
  pip install "lightrag-hku[api]"
9
  ```
10
 
11
- ### 2. Installation from Source (Development)
12
 
13
  ```bash
14
  # Clone the repository
@@ -22,33 +22,80 @@ cd lightrag
22
  pip install -e ".[api]"
23
  ```
24
 
25
- ### Prerequisites
 
 
 
 
 
 
 
26
 
27
  Before running any of the servers, ensure you have the corresponding backend service running for both llm and embedding.
28
- The new api allows you to mix different bindings for llm/embeddings.
29
- For example, you have the possibility to use ollama for the embedding and openai for the llm.
30
-
31
- #### For LoLLMs Server
32
- - LoLLMs must be running and accessible
33
- - Default connection: http://localhost:9600
34
- - Configure using --llm-binding-host and/or --embedding-binding-host if running on a different host/port
35
-
36
- #### For Ollama Server
37
- - Ollama must be running and accessible
38
- - Requires environment variables setup or command line argument provided
39
- - Environment variables: LLM_BINDING=ollama, LLM_BINDING_HOST, LLM_MODEL
40
- - Command line arguments: --llm-binding=ollama, --llm-binding-host, --llm-model
41
- - Default connection is http://localhost:11434 if not priveded
42
-
43
- > The default MAX_TOKENS(num_ctx) for Ollama is 32768. If your Ollama server is lacking or GPU memory, set it to a lower value.
44
-
45
- #### For OpenAI Alike Server
46
- - Requires environment variables setup or command line argument provided
47
- - Environment variables: LLM_BINDING=ollama, LLM_BINDING_HOST, LLM_MODEL, LLM_BINDING_API_KEY
48
- - Command line arguments: --llm-binding=ollama, --llm-binding-host, --llm-model, --llm-binding-api-key
49
- - Default connection is https://api.openai.com/v1 if not priveded
50
-
51
- #### For Azure OpenAI Server
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  Azure OpenAI API can be created using the following commands in Azure CLI (you need to install Azure CLI first from [https://docs.microsoft.com/en-us/cli/azure/install-azure-cli](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)):
53
  ```bash
54
  # Change the resource group name, location and OpenAI resource name as needed
@@ -68,13 +115,18 @@ az cognitiveservices account keys list --name $RESOURCE_NAME -g $RESOURCE_GROUP_
68
  The output of the last command will give you the endpoint and the key for the OpenAI API. You can use these values to set the environment variables in the `.env` file.
69
 
70
  ```
 
71
  LLM_BINDING=azure_openai
72
- LLM_BINDING_HOST=endpoint_of_azure_ai
73
- LLM_MODEL=model_name_of_azure_ai
74
- LLM_BINDING_API_KEY=api_key_of_azure_ai
 
 
 
 
75
  ```
76
 
77
- ### 3. Install Lightrag as a Linux Service
78
 
79
  Create a your service file `lightrag.sevice` from the sample file : `lightrag.sevice.example`. Modified the WorkingDirectoryand EexecStart in the service file:
80
 
@@ -105,40 +157,36 @@ sudo systemctl status lightrag.service
105
  sudo systemctl enable lightrag.service
106
  ```
107
 
 
108
 
 
109
 
110
- ## Configuration
111
-
112
- LightRAG can be configured using either command-line arguments or environment variables. When both are provided, command-line arguments take precedence over environment variables.
113
-
114
- Default `TOP_K` is set to `60`. Default `COSINE_THRESHOLD` are set to `0.2`.
115
 
116
- ### Environment Variables
117
 
118
- You can configure LightRAG using environment variables by creating a `.env` file in your project root directory. A sample file `.env.example` is provided for your convenience.
119
 
120
- ### Config.ini
121
 
122
- Datastorage configuration can be also set by config.ini. A sample file `config.ini.example` is provided for your convenience.
 
 
123
 
124
- ### Configuration Priority
125
 
126
- The configuration values are loaded in the following order (highest priority first):
127
- 1. Command-line arguments
128
- 2. Environment variables
129
- 3. Config.ini
130
- 4. Defaul values
131
 
132
- For example:
133
- ```bash
134
- # This command-line argument will override both the environment variable and default value
135
- python lightrag.py --port 8080
136
 
137
- # The environment variable will override the default value but not the command-line argument
138
- PORT=7000 python lightrag.py
139
- ```
 
140
 
141
- > Best practices: you can set your database setting in Config.ini while testing, and you use .env for production.
142
 
143
  ### Storage Types Supported
144
 
@@ -199,7 +247,16 @@ MongoDocStatusStorage MongoDB
199
 
200
  ### How Select Storage Implementation
201
 
202
- You can select storage implementation by enviroment variables or command line arguments. You can not change storage implementation selection after you add documents to LightRAG. Data migration from one storage implementation to anthor is not supported yet. For further information please read the sample env file or config.ini file.
 
 
 
 
 
 
 
 
 
203
 
204
  ### LightRag API Server Comand Line Options
205
 
@@ -207,32 +264,22 @@ You can select storage implementation by enviroment variables or command line a
207
  |-----------|---------|-------------|
208
  | --host | 0.0.0.0 | Server host |
209
  | --port | 9621 | Server port |
210
- | --llm-binding | ollama | LLM binding to be used. Supported: lollms, ollama, openai |
211
- | --llm-binding-host | (dynamic) | LLM server host URL. Defaults based on binding: http://localhost:11434 (ollama), http://localhost:9600 (lollms), https://api.openai.com/v1 (openai) |
212
- | --llm-model | mistral-nemo:latest | LLM model name |
213
- | --llm-binding-api-key | None | API Key for OpenAI Alike LLM |
214
- | --embedding-binding | ollama | Embedding binding to be used. Supported: lollms, ollama, openai |
215
- | --embedding-binding-host | (dynamic) | Embedding server host URL. Defaults based on binding: http://localhost:11434 (ollama), http://localhost:9600 (lollms), https://api.openai.com/v1 (openai) |
216
- | --embedding-model | bge-m3:latest | Embedding model name |
217
  | --working-dir | ./rag_storage | Working directory for RAG storage |
218
  | --input-dir | ./inputs | Directory containing input documents |
219
  | --max-async | 4 | Maximum async operations |
220
  | --max-tokens | 32768 | Maximum token size |
221
- | --embedding-dim | 1024 | Embedding dimensions |
222
- | --max-embed-tokens | 8192 | Maximum embedding token size |
223
  | --timeout | None | Timeout in seconds (useful when using slow AI). Use None for infinite timeout |
224
  | --log-level | INFO | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
225
- | --verbose | False | Verbose debug output (True, Flase) |
226
  | --key | None | API key for authentication. Protects lightrag server against unauthorized access |
227
  | --ssl | False | Enable HTTPS |
228
  | --ssl-certfile | None | Path to SSL certificate file (required if --ssl is enabled) |
229
  | --ssl-keyfile | None | Path to SSL private key file (required if --ssl is enabled) |
230
  | --top-k | 50 | Number of top-k items to retrieve; corresponds to entities in "local" mode and relationships in "global" mode. |
231
  | --cosine-threshold | 0.4 | The cossine threshold for nodes and relations retrieval, works with top-k to control the retrieval of nodes and relations. |
232
- | --kv-storage | JsonKVStorage | implement-name of KV_STORAGE |
233
- | --graph-storage | NetworkXStorage | implement-name of GRAPH_STORAGE |
234
- | --vector-storage | NanoVectorDBStorage | implement-name of VECTOR_STORAGE |
235
- | --doc-status-storage | JsonDocStatusStorage | implement-name of DOC_STATUS_STORAGE |
236
 
237
  ### Example Usage
238
 
@@ -244,57 +291,49 @@ Ollama is the default backend for both llm and embedding, so by default you can
244
  # Run lightrag with ollama, mistral-nemo:latest for llm, and bge-m3:latest for embedding
245
  lightrag-server
246
 
247
- # Using specific models (ensure they are installed in your ollama instance)
248
- lightrag-server --llm-model adrienbrault/nous-hermes2theta-llama3-8b:f16 --embedding-model nomic-embed-text --embedding-dim 1024
249
-
250
  # Using an authentication key
251
  lightrag-server --key my-key
252
-
253
- # Using lollms for llm and ollama for embedding
254
- lightrag-server --llm-binding lollms
255
  ```
256
 
257
  #### Running a Lightrag server with lollms default local server as llm and embedding backends
258
 
259
  ```bash
260
- # Run lightrag with lollms, mistral-nemo:latest for llm, and bge-m3:latest for embedding, use lollms for both llm and embedding
261
- lightrag-server --llm-binding lollms --embedding-binding lollms
262
-
263
- # Using specific models (ensure they are installed in your ollama instance)
264
- lightrag-server --llm-binding lollms --llm-model adrienbrault/nous-hermes2theta-llama3-8b:f16 --embedding-binding lollms --embedding-model nomic-embed-text --embedding-dim 1024
265
 
266
  # Using an authentication key
267
  lightrag-server --key my-key
268
-
269
- # Using lollms for llm and openai for embedding
270
- lightrag-server --llm-binding lollms --embedding-binding openai --embedding-model text-embedding-3-small
271
  ```
272
 
273
-
274
  #### Running a Lightrag server with openai server as llm and embedding backends
275
 
276
  ```bash
277
- # Run lightrag with lollms, GPT-4o-mini for llm, and text-embedding-3-small for embedding, use openai for both llm and embedding
278
- lightrag-server --llm-binding openai --llm-model GPT-4o-mini --embedding-binding openai --embedding-model text-embedding-3-small
 
 
 
 
 
279
 
280
  # Using an authentication key
281
- lightrag-server --llm-binding openai --llm-model GPT-4o-mini --embedding-binding openai --embedding-model text-embedding-3-small --key my-key
282
-
283
- # Using lollms for llm and openai for embedding
284
- lightrag-server --llm-binding lollms --embedding-binding openai --embedding-model text-embedding-3-small
285
  ```
286
 
287
  #### Running a Lightrag server with azure openai server as llm and embedding backends
288
 
289
  ```bash
290
- # Run lightrag with lollms, GPT-4o-mini for llm, and text-embedding-3-small for embedding, use openai for both llm and embedding
291
- lightrag-server --llm-binding azure_openai --llm-model GPT-4o-mini --embedding-binding openai --embedding-model text-embedding-3-small
 
 
 
 
 
292
 
293
  # Using an authentication key
294
- lightrag-server --llm-binding azure_openai --llm-model GPT-4o-mini --embedding-binding azure_openai --embedding-model text-embedding-3-small --key my-key
295
-
296
- # Using lollms for llm and azure_openai for embedding
297
- lightrag-server --llm-binding lollms --embedding-binding azure_openai --embedding-model text-embedding-3-small
298
  ```
299
 
300
  **Important Notes:**
@@ -315,7 +354,18 @@ pip install lightrag-hku
315
 
316
  ## API Endpoints
317
 
318
- All servers (LoLLMs, Ollama, OpenAI and Azure OpenAI) provide the same REST API endpoints for RAG functionality.
 
 
 
 
 
 
 
 
 
 
 
319
 
320
  ### Query Endpoints
321
 
@@ -453,62 +503,3 @@ For example, chat message "/mix 唐僧有几个徒弟" will trigger a mix mode q
453
 
454
  "/bypass" is not a LightRAG query mode, it will tell API Server to pass the query directly to the underlying LLM with chat history. So user can use LLM to answer question base on the chat history. If you are using Open WebUI as front end, you can just switch the model to a normal LLM instead of using /bypass prefix.
455
 
456
- ## Development
457
-
458
- Contribute to the project: [Guide](contributor-readme.MD)
459
-
460
- ### Running in Development Mode
461
-
462
- For LoLLMs:
463
- ```bash
464
- uvicorn lollms_lightrag_server:app --reload --port 9621
465
- ```
466
-
467
- For Ollama:
468
- ```bash
469
- uvicorn ollama_lightrag_server:app --reload --port 9621
470
- ```
471
-
472
- For OpenAI:
473
- ```bash
474
- uvicorn openai_lightrag_server:app --reload --port 9621
475
- ```
476
- For Azure OpenAI:
477
- ```bash
478
- uvicorn azure_openai_lightrag_server:app --reload --port 9621
479
- ```
480
- ### API Documentation
481
-
482
- When any server is running, visit:
483
- - Swagger UI: http://localhost:9621/docs
484
- - ReDoc: http://localhost:9621/redoc
485
-
486
- ### Testing API Endpoints
487
-
488
- You can test the API endpoints using the provided curl commands or through the Swagger UI interface. Make sure to:
489
- 1. Start the appropriate backend service (LoLLMs, Ollama, or OpenAI)
490
- 2. Start the RAG server
491
- 3. Upload some documents using the document management endpoints
492
- 4. Query the system using the query endpoints
493
- 5. Trigger document scan if new files is put into inputs directory
494
-
495
- ### Important Features
496
-
497
- #### Automatic Document Vectorization
498
- When starting any of the servers with the `--input-dir` parameter, the system will automatically:
499
- 1. Check for existing vectorized content in the database
500
- 2. Only vectorize new documents that aren't already in the database
501
- 3. Make all content immediately available for RAG queries
502
-
503
- This intelligent caching mechanism:
504
- - Prevents unnecessary re-vectorization of existing documents
505
- - Reduces startup time for subsequent runs
506
- - Preserves system resources
507
- - Maintains consistency across restarts
508
-
509
- **Important Notes:**
510
- - The `--input-dir` parameter enables automatic document processing at startup
511
- - Documents already in the database are not re-vectorized
512
- - Only new documents in the input directory will be processed
513
- - This optimization significantly reduces startup time for subsequent runs
514
- - The working directory (`--working-dir`) stores the vectorized documents database
 
1
+ ## Install LightRAG as an API Server
2
 
3
+ LightRAG provides optional API support through FastAPI servers that add RAG capabilities to existing LLM services. You can install LightRAG API Server in two ways:
4
 
5
+ ### Installation from PyPI
6
 
7
  ```bash
8
  pip install "lightrag-hku[api]"
9
  ```
10
 
11
+ ### Installation from Source (Development)
12
 
13
  ```bash
14
  # Clone the repository
 
22
  pip install -e ".[api]"
23
  ```
24
 
25
+ ### Starting API Server with Default Settings
26
+
27
+ LightRAG requires both LLM and Embedding Model to work together to complete document indexing and querying tasks. LightRAG supports binding to various LLM/Embedding backends:
28
+
29
+ * ollama
30
+ * lollms
31
+ * openai & openai compatible
32
+ * azure_openai
33
 
34
  Before running any of the servers, ensure you have the corresponding backend service running for both llm and embedding.
35
+ The LightRAG API Server provides default parameters for LLM and Embedding, allowing users to easily start the service through command line. These default configurations are:
36
+
37
+ * Default endpoint of LLM/Embeding backend(LLM_BINDING_HOST or EMBEDDING_BINDING_HOST)
38
+
39
+ ```
40
+ # for lollms backend
41
+ LLM_BINDING_HOST=http://localhost:11434
42
+ EMBEDDING_BINDING_HOST=http://localhost:11434
43
+
44
+ # for lollms backend
45
+ LLM_BINDING_HOST=http://localhost:9600
46
+ EMBEDDING_BINDING_HOST=http://localhost:9600
47
+
48
+ # for openai, openai compatible or azure openai backend
49
+ LLM_BINDING_HOST=https://api.openai.com/v1
50
+ EMBEDDING_BINDING_HOST=http://localhost:9600
51
+ ```
52
+
53
+ * Default model config
54
+
55
+ ```
56
+ LLM_MODEL=mistral-nemo:latest
57
+
58
+ EMBEDDING_MODEL=bge-m3:latest
59
+ EMBEDDING_DIM=1024
60
+ MAX_EMBED_TOKENS=8192
61
+ ```
62
+
63
+ * API keys for LLM/Embedding backend
64
+
65
+ When connecting to backend require API KEY, corresponding environment variables must be provided:
66
+
67
+ ```
68
+ LLM_BINDING_API_KEY=your_api_key
69
+ EMBEDDING_BINDING_API_KEY=your_api_key
70
+ ```
71
+
72
+ * Use command line arguments to choose LLM/Embeding backend
73
+
74
+ Use `--llm-binding` to select LLM backend type, and use `--embedding-binding` to select the embedding backend type. All the supported backend types are:
75
+
76
+ ```
77
+ openai: LLM default type
78
+ ollama: Embedding defult type
79
+ lollms:
80
+ azure_openai:
81
+ openai-ollama: select openai for LLM and ollama for embedding(only valid for --llm-binding)
82
+ ```
83
+
84
+ The LightRAG API Server allows you to mix different bindings for llm/embeddings. For example, you have the possibility to use ollama for the embedding and openai for the llm.With the above default parameters, you can start API Server with simple CLI arguments like these:
85
+
86
+ ```
87
+ # start with openai llm and ollama embedding
88
+ LLM_BINDING_API_KEY=your_api_key Light_server
89
+ LLM_BINDING_API_KEY=your_api_key Light_server --llm-binding openai-ollama
90
+
91
+ # start with openai llm and openai embedding
92
+ LLM_BINDING_API_KEY=your_api_key Light_server --llm-binding openai --embedding-binding openai
93
+
94
+ # start with ollama llm and ollama embedding (no apikey is needed)
95
+ Light_server --llm-binding ollama --embedding-binding ollama
96
+ ```
97
+
98
+ ### For Azure OpenAI Backend
99
  Azure OpenAI API can be created using the following commands in Azure CLI (you need to install Azure CLI first from [https://docs.microsoft.com/en-us/cli/azure/install-azure-cli](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)):
100
  ```bash
101
  # Change the resource group name, location and OpenAI resource name as needed
 
115
  The output of the last command will give you the endpoint and the key for the OpenAI API. You can use these values to set the environment variables in the `.env` file.
116
 
117
  ```
118
+ # Azure OpenAI Configuration in .env
119
  LLM_BINDING=azure_openai
120
+ LLM_BINDING_HOST=your-azure-endpoint
121
+ LLM_MODEL=your-model-deployment-name
122
+ LLM_BINDING_API_KEY=your-azure-api-key
123
+ AZURE_OPENAI_API_VERSION=2024-08-01-preview # optional, defaults to latest version
124
+ EMBEDDING_BINDING=azure_openai # if using Azure OpenAI for embeddings
125
+ EMBEDDING_MODEL=your-embedding-deployment-name
126
+
127
  ```
128
 
129
+ ### Install Lightrag as a Linux Service
130
 
131
  Create a your service file `lightrag.sevice` from the sample file : `lightrag.sevice.example`. Modified the WorkingDirectoryand EexecStart in the service file:
132
 
 
157
  sudo systemctl enable lightrag.service
158
  ```
159
 
160
+ ### Automatic Document Indexing
161
 
162
+ When starting any of the servers with the `--auto-scan-at-startup` parameter, the system will automatically:
163
 
164
+ 1. Scan for new files in the input directory
165
+ 2. Indexing new documents that aren't already in the database
166
+ 3. Make all content immediately available for RAG queries
 
 
167
 
168
+ > The `--input-dir` parameter specify the input directory to scan for.
169
 
170
+ ## API Server Configuration
171
 
172
+ API Server can be config in three way (highest priority first):
173
 
174
+ * Command line arguments
175
+ * Enviroment variables or .env file
176
+ * Config.ini (Only for storage configuration)
177
 
178
+ Most of the configurations come with a default settings, check out details in sample file: `.env.example`. Datastorage configuration can be also set by config.ini. A sample file `config.ini.example` is provided for your convenience.
179
 
180
+ ### LLM and Embedding Backend Supported
 
 
 
 
181
 
182
+ LightRAG supports binding to various LLM/Embedding backends:
 
 
 
183
 
184
+ * ollama
185
+ * lollms
186
+ * openai & openai compatible
187
+ * azure_openai
188
 
189
+ Use environment variables `LLM_BINDING ` or CLI argument `--llm-binding` to select LLM backend type. Use environment variables `EMBEDDING_BINDING ` or CLI argument `--embedding-binding` to select LLM backend type.
190
 
191
  ### Storage Types Supported
192
 
 
247
 
248
  ### How Select Storage Implementation
249
 
250
+ You can select storage implementation by environment variables. Your can set the following environmental variables to a specific storage implement-name before the your first start of the API Server:
251
+
252
+ ```
253
+ LIGHTRAG_KV_STORAGE=PGKVStorage
254
+ LIGHTRAG_VECTOR_STORAGE=PGVectorStorage
255
+ LIGHTRAG_GRAPH_STORAGE=PGGraphStorage
256
+ LIGHTRAG_DOC_STATUS_STORAGE=PGDocStatusStorage
257
+ ```
258
+
259
+ You can not change storage implementation selection after you add documents to LightRAG. Data migration from one storage implementation to anthor is not supported yet. For further information please read the sample env file or config.ini file.
260
 
261
  ### LightRag API Server Comand Line Options
262
 
 
264
  |-----------|---------|-------------|
265
  | --host | 0.0.0.0 | Server host |
266
  | --port | 9621 | Server port |
 
 
 
 
 
 
 
267
  | --working-dir | ./rag_storage | Working directory for RAG storage |
268
  | --input-dir | ./inputs | Directory containing input documents |
269
  | --max-async | 4 | Maximum async operations |
270
  | --max-tokens | 32768 | Maximum token size |
 
 
271
  | --timeout | None | Timeout in seconds (useful when using slow AI). Use None for infinite timeout |
272
  | --log-level | INFO | Logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
273
+ | --verbose | - | Verbose debug output (True, Flase) |
274
  | --key | None | API key for authentication. Protects lightrag server against unauthorized access |
275
  | --ssl | False | Enable HTTPS |
276
  | --ssl-certfile | None | Path to SSL certificate file (required if --ssl is enabled) |
277
  | --ssl-keyfile | None | Path to SSL private key file (required if --ssl is enabled) |
278
  | --top-k | 50 | Number of top-k items to retrieve; corresponds to entities in "local" mode and relationships in "global" mode. |
279
  | --cosine-threshold | 0.4 | The cossine threshold for nodes and relations retrieval, works with top-k to control the retrieval of nodes and relations. |
280
+ | --llm-binding | ollama | LLM binding type (lollms, ollama, openai, openai-ollama, azure_openai) |
281
+ | --embedding-binding | ollama | Embedding binding type (lollms, ollama, openai, azure_openai) |
282
+ | auto-scan-at-startup | - | Scan input directory for new files and start indexing |
 
283
 
284
  ### Example Usage
285
 
 
291
  # Run lightrag with ollama, mistral-nemo:latest for llm, and bge-m3:latest for embedding
292
  lightrag-server
293
 
 
 
 
294
  # Using an authentication key
295
  lightrag-server --key my-key
 
 
 
296
  ```
297
 
298
  #### Running a Lightrag server with lollms default local server as llm and embedding backends
299
 
300
  ```bash
301
+ # Run lightrag with lollms, mistral-nemo:latest for llm, and bge-m3:latest for embedding
302
+ # Configure LLM_BINDING=lollms and EMBEDDING_BINDING=lollms in .env or config.ini
303
+ lightrag-server
 
 
304
 
305
  # Using an authentication key
306
  lightrag-server --key my-key
 
 
 
307
  ```
308
 
 
309
  #### Running a Lightrag server with openai server as llm and embedding backends
310
 
311
  ```bash
312
+ # Run lightrag with openai, GPT-4o-mini for llm, and text-embedding-3-small for embedding
313
+ # Configure in .env or config.ini:
314
+ # LLM_BINDING=openai
315
+ # LLM_MODEL=GPT-4o-mini
316
+ # EMBEDDING_BINDING=openai
317
+ # EMBEDDING_MODEL=text-embedding-3-small
318
+ lightrag-server
319
 
320
  # Using an authentication key
321
+ lightrag-server --key my-key
 
 
 
322
  ```
323
 
324
  #### Running a Lightrag server with azure openai server as llm and embedding backends
325
 
326
  ```bash
327
+ # Run lightrag with azure_openai
328
+ # Configure in .env or config.ini:
329
+ # LLM_BINDING=azure_openai
330
+ # LLM_MODEL=your-model
331
+ # EMBEDDING_BINDING=azure_openai
332
+ # EMBEDDING_MODEL=your-embedding-model
333
+ lightrag-server
334
 
335
  # Using an authentication key
336
+ lightrag-server --key my-key
 
 
 
337
  ```
338
 
339
  **Important Notes:**
 
354
 
355
  ## API Endpoints
356
 
357
+ All servers (LoLLMs, Ollama, OpenAI and Azure OpenAI) provide the same REST API endpoints for RAG functionality. When API Server is running, visit:
358
+
359
+ - Swagger UI: http://localhost:9621/docs
360
+ - ReDoc: http://localhost:9621/redoc
361
+
362
+ You can test the API endpoints using the provided curl commands or through the Swagger UI interface. Make sure to:
363
+
364
+ 1. Start the appropriate backend service (LoLLMs, Ollama, or OpenAI)
365
+ 2. Start the RAG server
366
+ 3. Upload some documents using the document management endpoints
367
+ 4. Query the system using the query endpoints
368
+ 5. Trigger document scan if new files is put into inputs directory
369
 
370
  ### Query Endpoints
371
 
 
503
 
504
  "/bypass" is not a LightRAG query mode, it will tell API Server to pass the query directly to the underlying LLM with chat history. So user can use LLM to answer question base on the chat history. If you are using Open WebUI as front end, you can just switch the model to a normal LLM instead of using /bypass prefix.
505