ParisNeo commited on
Commit
d3f0362
·
1 Parent(s): 20a5942

Added azure openai lightrag server to the api install and fused documentation.

Browse files
README.md CHANGED
@@ -598,120 +598,6 @@ if __name__ == "__main__":
598
  | **convert\_response\_to\_json\_func** | `callable` | Not used | `convert_response_to_json` |
599
  | **embedding\_cache\_config** | `dict` | Configuration for question-answer caching. Contains three parameters:<br>- `enabled`: Boolean value to enable/disable cache lookup functionality. When enabled, the system will check cached responses before generating new answers.<br>- `similarity_threshold`: Float value (0-1), similarity threshold. When a new question's similarity with a cached question exceeds this threshold, the cached answer will be returned directly without calling the LLM.<br>- `use_llm_check`: Boolean value to enable/disable LLM similarity verification. When enabled, LLM will be used as a secondary check to verify the similarity between questions before returning cached answers. | Default: `{"enabled": False, "similarity_threshold": 0.95, "use_llm_check": False}` |
600
 
601
- ## API Server Implementation
602
-
603
- LightRAG also provides a FastAPI-based server implementation for RESTful API access to RAG operations. This allows you to run LightRAG as a service and interact with it through HTTP requests.
604
-
605
- ### Setting up the API Server
606
- <details>
607
- <summary>Click to expand setup instructions</summary>
608
-
609
- 1. First, ensure you have the required dependencies:
610
- ```bash
611
- pip install fastapi uvicorn pydantic
612
- ```
613
-
614
- 2. Set up your environment variables:
615
- ```bash
616
- export RAG_DIR="your_index_directory" # Optional: Defaults to "index_default"
617
- export OPENAI_BASE_URL="Your OpenAI API base URL" # Optional: Defaults to "https://api.openai.com/v1"
618
- export OPENAI_API_KEY="Your OpenAI API key" # Required
619
- export LLM_MODEL="Your LLM model" # Optional: Defaults to "gpt-4o-mini"
620
- export EMBEDDING_MODEL="Your embedding model" # Optional: Defaults to "text-embedding-3-large"
621
- ```
622
-
623
- 3. Run the API server:
624
- ```bash
625
- python examples/lightrag_api_openai_compatible_demo.py
626
- ```
627
-
628
- The server will start on `http://0.0.0.0:8020`.
629
- </details>
630
-
631
- ### API Endpoints
632
-
633
- The API server provides the following endpoints:
634
-
635
- #### 1. Query Endpoint
636
- <details>
637
- <summary>Click to view Query endpoint details</summary>
638
-
639
- - **URL:** `/query`
640
- - **Method:** POST
641
- - **Body:**
642
- ```json
643
- {
644
- "query": "Your question here",
645
- "mode": "hybrid", // Can be "naive", "local", "global", or "hybrid"
646
- "only_need_context": true // Optional: Defaults to false, if true, only the referenced context will be returned, otherwise the llm answer will be returned
647
- }
648
- ```
649
- - **Example:**
650
- ```bash
651
- curl -X POST "http://127.0.0.1:8020/query" \
652
- -H "Content-Type: application/json" \
653
- -d '{"query": "What are the main themes?", "mode": "hybrid"}'
654
- ```
655
- </details>
656
-
657
- #### 2. Insert Text Endpoint
658
- <details>
659
- <summary>Click to view Insert Text endpoint details</summary>
660
-
661
- - **URL:** `/insert`
662
- - **Method:** POST
663
- - **Body:**
664
- ```json
665
- {
666
- "text": "Your text content here"
667
- }
668
- ```
669
- - **Example:**
670
- ```bash
671
- curl -X POST "http://127.0.0.1:8020/insert" \
672
- -H "Content-Type: application/json" \
673
- -d '{"text": "Content to be inserted into RAG"}'
674
- ```
675
- </details>
676
-
677
- #### 3. Insert File Endpoint
678
- <details>
679
- <summary>Click to view Insert File endpoint details</summary>
680
-
681
- - **URL:** `/insert_file`
682
- - **Method:** POST
683
- - **Body:**
684
- ```json
685
- {
686
- "file_path": "path/to/your/file.txt"
687
- }
688
- ```
689
- - **Example:**
690
- ```bash
691
- curl -X POST "http://127.0.0.1:8020/insert_file" \
692
- -H "Content-Type: application/json" \
693
- -d '{"file_path": "./book.txt"}'
694
- ```
695
- </details>
696
-
697
- #### 4. Health Check Endpoint
698
- <details>
699
- <summary>Click to view Health Check endpoint details</summary>
700
-
701
- - **URL:** `/health`
702
- - **Method:** GET
703
- - **Example:**
704
- ```bash
705
- curl -X GET "http://127.0.0.1:8020/health"
706
- ```
707
- </details>
708
-
709
- ### Configuration
710
-
711
- The API server can be configured using environment variables:
712
- - `RAG_DIR`: Directory for storing the RAG index (default: "index_default")
713
- - API keys and base URLs should be configured in the code for your specific LLM and embedding model providers
714
-
715
  ### Error Handling
716
  <details>
717
  <summary>Click to view error handling details</summary>
@@ -989,6 +875,12 @@ def extract_queries(file_path):
989
  │ ├── lightrag_siliconcloud_demo.py
990
  │ └── vram_management_demo.py
991
  ├── lightrag/
 
 
 
 
 
 
992
  │ ├── kg/
993
  │ │ ├── __init__.py
994
  │ │ ├── oracle_impl.py
@@ -1033,7 +925,7 @@ pip install "lightrag-hku[api]"
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
@@ -1060,6 +952,27 @@ Before running any of the servers, ensure you have the corresponding backend ser
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:
@@ -1112,6 +1025,22 @@ Each server has its own specific configuration options:
1112
  | --input-dir | ./inputs | Input directory for documents |
1113
  | --log-level | INFO | Logging level |
1114
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1115
  ### Example Usage
1116
 
1117
  #### LoLLMs RAG Server
@@ -1140,17 +1069,25 @@ ollama-lightrag-server --model mistral-nemo:latest --embedding-model bge-m3 --em
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:
@@ -1160,7 +1097,7 @@ pip install lightrag-hku
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
 
@@ -1245,7 +1182,10 @@ 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:
@@ -1301,6 +1241,14 @@ ollama-lightrag-server --input-dir ./my_documents --port 8080
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
 
598
  | **convert\_response\_to\_json\_func** | `callable` | Not used | `convert_response_to_json` |
599
  | **embedding\_cache\_config** | `dict` | Configuration for question-answer caching. Contains three parameters:<br>- `enabled`: Boolean value to enable/disable cache lookup functionality. When enabled, the system will check cached responses before generating new answers.<br>- `similarity_threshold`: Float value (0-1), similarity threshold. When a new question's similarity with a cached question exceeds this threshold, the cached answer will be returned directly without calling the LLM.<br>- `use_llm_check`: Boolean value to enable/disable LLM similarity verification. When enabled, LLM will be used as a secondary check to verify the similarity between questions before returning cached answers. | Default: `{"enabled": False, "similarity_threshold": 0.95, "use_llm_check": False}` |
600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  ### Error Handling
602
  <details>
603
  <summary>Click to view error handling details</summary>
 
875
  │ ├── lightrag_siliconcloud_demo.py
876
  │ └── vram_management_demo.py
877
  ├── lightrag/
878
+ │ ├── api/
879
+ │ │ ├── lollms_lightrag_server.py
880
+ │ │ ├── ollama_lightrag_server.py
881
+ │ │ ├── openai_lightrag_server.py
882
+ │ │ ├── azure_openai_lightrag_server.py
883
+ │ │ └── requirements.txt
884
  │ ├── kg/
885
  │ │ ├── __init__.py
886
  │ │ ├── oracle_impl.py
 
925
 
926
  ```bash
927
  # Clone the repository
928
+ git clone https://github.com/HKUDS/lightrag.git
929
 
930
  # Change to the repository directory
931
  cd lightrag
 
952
  - Requires valid OpenAI API credentials set in environment variables
953
  - OPENAI_API_KEY must be set
954
 
955
+ #### For Azure OpenAI Server
956
+ 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)):
957
+ ```bash
958
+ # Change the resource group name, location and OpenAI resource name as needed
959
+ RESOURCE_GROUP_NAME=LightRAG
960
+ LOCATION=swedencentral
961
+ RESOURCE_NAME=LightRAG-OpenAI
962
+
963
+ az login
964
+ az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
965
+ az cognitiveservices account create --name $RESOURCE_NAME --resource-group $RESOURCE_GROUP_NAME --kind OpenAI --sku S0 --location swedencentral
966
+ az cognitiveservices account deployment create --resource-group $RESOURCE_GROUP_NAME --model-format OpenAI --name $RESOURCE_NAME --deployment-name gpt-4o --model-name gpt-4o --model-version "2024-08-06" --sku-capacity 100 --sku-name "Standard"
967
+ az cognitiveservices account deployment create --resource-group $RESOURCE_GROUP_NAME --model-format OpenAI --name $RESOURCE_NAME --deployment-name text-embedding-3-large --model-name text-embedding-3-large --model-version "1" --sku-capacity 80 --sku-name "Standard"
968
+ az cognitiveservices account show --name $RESOURCE_NAME --resource-group $RESOURCE_GROUP_NAME --query "properties.endpoint"
969
+ az cognitiveservices account keys list --name $RESOURCE_NAME -g $RESOURCE_GROUP_NAME
970
+
971
+ ```
972
+ 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.
973
+
974
+
975
+
976
  ### Configuration Options
977
 
978
  Each server has its own specific configuration options:
 
1025
  | --input-dir | ./inputs | Input directory for documents |
1026
  | --log-level | INFO | Logging level |
1027
 
1028
+ #### OpenAI AZURE Server Options
1029
+
1030
+ | Parameter | Default | Description |
1031
+ |-----------|---------|-------------|
1032
+ | --host | 0.0.0.0 | Server host |
1033
+ | --port | 9621 | Server port |
1034
+ | --model | gpt-4 | OpenAI model name |
1035
+ | --embedding-model | text-embedding-3-large | OpenAI embedding model |
1036
+ | --working-dir | ./rag_storage | Working directory for RAG |
1037
+ | --max-tokens | 32768 | Maximum token size |
1038
+ | --max-embed-tokens | 8192 | Maximum embedding token size |
1039
+ | --input-dir | ./inputs | Input directory for documents |
1040
+ | --enable-cache | True | Enable response cache |
1041
+ | --log-level | INFO | Logging level |
1042
+
1043
+
1044
  ### Example Usage
1045
 
1046
  #### LoLLMs RAG Server
 
1069
  # Using GPT-4 with text-embedding-3-large
1070
  openai-lightrag-server --port 9624 --model gpt-4 --embedding-model text-embedding-3-large
1071
  ```
1072
+ #### Azure OpenAI RAG Server
1073
+ ```bash
1074
+ # Using GPT-4 with text-embedding-3-large
1075
+ azure-openai-lightrag-server --model gpt-4o --port 8080 --working-dir ./custom_rag --embedding-model text-embedding-3-large
1076
+ ```
1077
+
1078
 
1079
  **Important Notes:**
1080
  - For LoLLMs: Make sure the specified models are installed in your LoLLMs instance
1081
  - For Ollama: Make sure the specified models are installed in your Ollama instance
1082
  - For OpenAI: Ensure you have set up your OPENAI_API_KEY environment variable
1083
+ - For Azure OpenAI: Build and configure your server as stated in the Prequisites section
1084
 
1085
  For help on any server, use the --help flag:
1086
  ```bash
1087
  lollms-lightrag-server --help
1088
  ollama-lightrag-server --help
1089
  openai-lightrag-server --help
1090
+ azure-openai-lightrag-server --help
1091
  ```
1092
 
1093
  Note: If you don't need the API functionality, you can install the base package without API support using:
 
1097
 
1098
  ## API Endpoints
1099
 
1100
+ All servers (LoLLMs, Ollama, OpenAI and Azure OpenAI) provide the same REST API endpoints for RAG functionality.
1101
 
1102
  ### Query Endpoints
1103
 
 
1182
  ```bash
1183
  uvicorn openai_lightrag_server:app --reload --port 9621
1184
  ```
1185
+ For Azure OpenAI:
1186
+ ```bash
1187
+ uvicorn azure_openai_lightrag_server:app --reload --port 9621
1188
+ ```
1189
  ### API Documentation
1190
 
1191
  When any server is running, visit:
 
1241
  openai-lightrag-server --input-dir ./my_documents --port 9624
1242
  ```
1243
 
1244
+ #### Azure OpenAI RAG Server
1245
+
1246
+ ```bash
1247
+ # Start server with automatic document vectorization
1248
+ # Existing documents are retrieved from cache, only new ones are processed
1249
+ azure-openai-lightrag-server --input-dir ./my_documents --port 9624
1250
+ ```
1251
+
1252
  **Important Notes:**
1253
  - The `--input-dir` parameter enables automatic document processing at startup
1254
  - Documents already in the database are not re-vectorized
examples/openai_README.md ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ## API Server Implementation
3
+
4
+ LightRAG also provides a FastAPI-based server implementation for RESTful API access to RAG operations. This allows you to run LightRAG as a service and interact with it through HTTP requests.
5
+
6
+ ### Setting up the API Server
7
+ <details>
8
+ <summary>Click to expand setup instructions</summary>
9
+
10
+ 1. First, ensure you have the required dependencies:
11
+ ```bash
12
+ pip install fastapi uvicorn pydantic
13
+ ```
14
+
15
+ 2. Set up your environment variables:
16
+ ```bash
17
+ export RAG_DIR="your_index_directory" # Optional: Defaults to "index_default"
18
+ export OPENAI_BASE_URL="Your OpenAI API base URL" # Optional: Defaults to "https://api.openai.com/v1"
19
+ export OPENAI_API_KEY="Your OpenAI API key" # Required
20
+ export LLM_MODEL="Your LLM model" # Optional: Defaults to "gpt-4o-mini"
21
+ export EMBEDDING_MODEL="Your embedding model" # Optional: Defaults to "text-embedding-3-large"
22
+ ```
23
+
24
+ 3. Run the API server:
25
+ ```bash
26
+ python examples/lightrag_api_openai_compatible_demo.py
27
+ ```
28
+
29
+ The server will start on `http://0.0.0.0:8020`.
30
+ </details>
31
+
32
+ ### API Endpoints
33
+
34
+ The API server provides the following endpoints:
35
+
36
+ #### 1. Query Endpoint
37
+ <details>
38
+ <summary>Click to view Query endpoint details</summary>
39
+
40
+ - **URL:** `/query`
41
+ - **Method:** POST
42
+ - **Body:**
43
+ ```json
44
+ {
45
+ "query": "Your question here",
46
+ "mode": "hybrid", // Can be "naive", "local", "global", or "hybrid"
47
+ "only_need_context": true // Optional: Defaults to false, if true, only the referenced context will be returned, otherwise the llm answer will be returned
48
+ }
49
+ ```
50
+ - **Example:**
51
+ ```bash
52
+ curl -X POST "http://127.0.0.1:8020/query" \
53
+ -H "Content-Type: application/json" \
54
+ -d '{"query": "What are the main themes?", "mode": "hybrid"}'
55
+ ```
56
+ </details>
57
+
58
+ #### 2. Insert Text Endpoint
59
+ <details>
60
+ <summary>Click to view Insert Text endpoint details</summary>
61
+
62
+ - **URL:** `/insert`
63
+ - **Method:** POST
64
+ - **Body:**
65
+ ```json
66
+ {
67
+ "text": "Your text content here"
68
+ }
69
+ ```
70
+ - **Example:**
71
+ ```bash
72
+ curl -X POST "http://127.0.0.1:8020/insert" \
73
+ -H "Content-Type: application/json" \
74
+ -d '{"text": "Content to be inserted into RAG"}'
75
+ ```
76
+ </details>
77
+
78
+ #### 3. Insert File Endpoint
79
+ <details>
80
+ <summary>Click to view Insert File endpoint details</summary>
81
+
82
+ - **URL:** `/insert_file`
83
+ - **Method:** POST
84
+ - **Body:**
85
+ ```json
86
+ {
87
+ "file_path": "path/to/your/file.txt"
88
+ }
89
+ ```
90
+ - **Example:**
91
+ ```bash
92
+ curl -X POST "http://127.0.0.1:8020/insert_file" \
93
+ -H "Content-Type: application/json" \
94
+ -d '{"file_path": "./book.txt"}'
95
+ ```
96
+ </details>
97
+
98
+ #### 4. Health Check Endpoint
99
+ <details>
100
+ <summary>Click to view Health Check endpoint details</summary>
101
+
102
+ - **URL:** `/health`
103
+ - **Method:** GET
104
+ - **Example:**
105
+ ```bash
106
+ curl -X GET "http://127.0.0.1:8020/health"
107
+ ```
108
+ </details>
109
+
110
+ ### Configuration
111
+
112
+ The API server can be configured using environment variables:
113
+ - `RAG_DIR`: Directory for storing the RAG index (default: "index_default")
114
+ - API keys and base URLs should be configured in the code for your specific LLM and embedding model providers
lightrag/api/README_AZURE_OPENAI.md DELETED
@@ -1,202 +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
- - Azure OpenAI API key
20
- - Azure OpenAI Deployments (gpt-4o, text-embedding-3-large)
21
- - Required Python packages:
22
- - fastapi
23
- - uvicorn
24
- - lightrag
25
- - pydantic
26
- - openai
27
- - nest-asyncio
28
-
29
- ## Installation
30
- 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/)
31
- Make sure you install the VS 2022 C++ x64/x86 Build tools from individual components tab.
32
-
33
- 1. Clone the repository:
34
- ```bash
35
- git clone https://github.com/ParisNeo/LightRAG.git
36
- cd api
37
- ```
38
-
39
- 2. Install dependencies:
40
- ```bash
41
- python -m venv venv
42
- source venv/bin/activate
43
- #venv\Scripts\activate for Windows
44
- pip install -r requirements.txt
45
- ```
46
-
47
- 3. Set up environment variables:
48
- use the `.env` file to set the environment variables (you can copy the `.env.aoi.example` file and rename it to `.env`),
49
- or set them manually:
50
- ```bash
51
- export AZURE_OPENAI_API_VERSION='2024-08-01-preview'
52
- export AZURE_OPENAI_DEPLOYMENT='gpt-4o'
53
- export AZURE_OPENAI_API_KEY='myapikey'
54
- export AZURE_OPENAI_ENDPOINT='https://myendpoint.openai.azure.com'
55
- export AZURE_EMBEDDING_DEPLOYMENT='text-embedding-3-large'
56
- export AZURE_EMBEDDING_API_VERSION='2023-05-15'
57
- ```
58
-
59
- ## Configuration
60
-
61
- The server can be configured using command-line arguments:
62
-
63
- ```bash
64
- python azure_openai_lightrag_server.py --help
65
- ```
66
-
67
- Available options:
68
-
69
- | Parameter | Default | Description |
70
- |-----------|---------|-------------|
71
- | --host | 0.0.0.0 | Server host |
72
- | --port | 9621 | Server port |
73
- | --model | gpt-4 | OpenAI model name |
74
- | --embedding-model | text-embedding-3-large | OpenAI embedding model |
75
- | --working-dir | ./rag_storage | Working directory for RAG |
76
- | --max-tokens | 32768 | Maximum token size |
77
- | --max-embed-tokens | 8192 | Maximum embedding token size |
78
- | --input-dir | ./inputs | Input directory for documents |
79
- | --enable-cache | True | Enable response cache |
80
- | --log-level | INFO | Logging level |
81
-
82
- ## Quick Start
83
-
84
- 1. Basic usage with default settings:
85
- ```bash
86
- python azure_openai_lightrag_server.py
87
- ```
88
-
89
- 2. Custom configuration:
90
- ```bash
91
- python azure_openai_lightrag_server.py --model gpt-4o --port 8080 --working-dir ./custom_rag
92
- ```
93
-
94
- ## API Endpoints
95
-
96
- ### Query Endpoints
97
-
98
- #### POST /query
99
- Query the RAG system with options for different search modes.
100
-
101
- ```bash
102
- curl -X POST "http://localhost:9621/query" \
103
- -H "Content-Type: application/json" \
104
- -d '{"query": "Your question here", "mode": "hybrid"}'
105
- ```
106
-
107
- #### POST /query/stream
108
- Stream responses from the RAG system.
109
-
110
- ```bash
111
- curl -X POST "http://localhost:9621/query/stream" \
112
- -H "Content-Type: application/json" \
113
- -d '{"query": "Your question here", "mode": "hybrid"}'
114
- ```
115
-
116
- ### Document Management Endpoints
117
-
118
- #### POST /documents/text
119
- Insert text directly into the RAG system.
120
-
121
- ```bash
122
- curl -X POST "http://localhost:9621/documents/text" \
123
- -H "Content-Type: application/json" \
124
- -d '{"text": "Your text content here", "description": "Optional description"}'
125
- ```
126
-
127
- #### POST /documents/file
128
- Upload a single file to the RAG system.
129
-
130
- ```bash
131
- curl -X POST "http://localhost:9621/documents/file" \
132
- -F "file=@/path/to/your/document.txt" \
133
- -F "description=Optional description"
134
- ```
135
-
136
- #### POST /documents/batch
137
- Upload multiple files at once.
138
-
139
- ```bash
140
- curl -X POST "http://localhost:9621/documents/batch" \
141
- -F "files=@/path/to/doc1.txt" \
142
- -F "files=@/path/to/doc2.txt"
143
- ```
144
-
145
- #### DELETE /documents
146
- Clear all documents from the RAG system.
147
-
148
- ```bash
149
- curl -X DELETE "http://localhost:9621/documents"
150
- ```
151
-
152
- ### Utility Endpoints
153
-
154
- #### GET /health
155
- Check server health and configuration.
156
-
157
- ```bash
158
- curl "http://localhost:9621/health"
159
- ```
160
-
161
- ## Development
162
-
163
- ### Running in Development Mode
164
-
165
- ```bash
166
- uvicorn azure_openai_lightrag_server:app --reload --port 9621
167
- ```
168
-
169
- ### API Documentation
170
-
171
- When the server is running, visit:
172
- - Swagger UI: http://localhost:9621/docs
173
- - ReDoc: http://localhost:9621/redoc
174
-
175
- ## Deployment
176
- 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)):
177
- ```bash
178
- # Change the resource group name, location and OpenAI resource name as needed
179
- RESOURCE_GROUP_NAME=LightRAG
180
- LOCATION=swedencentral
181
- RESOURCE_NAME=LightRAG-OpenAI
182
-
183
- az login
184
- az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
185
- az cognitiveservices account create --name $RESOURCE_NAME --resource-group $RESOURCE_GROUP_NAME --kind OpenAI --sku S0 --location swedencentral
186
- az cognitiveservices account deployment create --resource-group $RESOURCE_GROUP_NAME --model-format OpenAI --name $RESOURCE_NAME --deployment-name gpt-4o --model-name gpt-4o --model-version "2024-08-06" --sku-capacity 100 --sku-name "Standard"
187
- az cognitiveservices account deployment create --resource-group $RESOURCE_GROUP_NAME --model-format OpenAI --name $RESOURCE_NAME --deployment-name text-embedding-3-large --model-name text-embedding-3-large --model-version "1" --sku-capacity 80 --sku-name "Standard"
188
- az cognitiveservices account show --name $RESOURCE_NAME --resource-group $RESOURCE_GROUP_NAME --query "properties.endpoint"
189
- az cognitiveservices account keys list --name $RESOURCE_NAME -g $RESOURCE_GROUP_NAME
190
-
191
- ```
192
- 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.
193
-
194
- ## License
195
-
196
- This project is licensed under the MIT License - see the LICENSE file for details.
197
-
198
- ## Acknowledgments
199
-
200
- - Built with [FastAPI](https://fastapi.tiangolo.com/)
201
- - Uses [LightRAG](https://github.com/HKUDS/LightRAG) for document processing
202
- - Powered by [OpenAI](https://openai.com/) for language model inference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
lightrag/api/azure_openai_lightrag_server.py CHANGED
@@ -435,9 +435,13 @@ def create_app(args):
435
  return app
436
 
437
 
438
- if __name__ == "__main__":
439
  args = parse_args()
440
  import uvicorn
441
 
442
  app = create_app(args)
443
  uvicorn.run(app, host=args.host, port=args.port)
 
 
 
 
 
435
  return app
436
 
437
 
438
+ def main():
439
  args = parse_args()
440
  import uvicorn
441
 
442
  app = create_app(args)
443
  uvicorn.run(app, host=args.host, port=args.port)
444
+
445
+
446
+ if __name__ == "__main__":
447
+ main()
setup.py CHANGED
@@ -103,6 +103,7 @@ setuptools.setup(
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
  )
 
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
+ "azure-openai-lightrag-server=lightrag.api.azure_openai_lightrag_server:main [api]",
107
  ],
108
  },
109
  )