yangdx commited on
Commit
7085743
·
1 Parent(s): c957306

docs: reorganize Ollama emulation API documentation for better readability

Browse files
Files changed (1) hide show
  1. lightrag/api/README.md +58 -48
lightrag/api/README.md CHANGED
@@ -74,30 +74,38 @@ LLM_MODEL=model_name_of_azure_ai
74
  LLM_BINDING_API_KEY=api_key_of_azure_ai
75
  ```
76
 
77
- ### About Ollama API
78
 
79
- We provide an Ollama-compatible interfaces for LightRAG, aiming to emulate LightRAG as an Ollama chat model. This allows AI chat frontends supporting Ollama, such as Open WebUI, to access LightRAG easily.
80
 
81
- #### Choose Query mode in chat
 
 
 
 
82
 
83
- A query prefix in the query string can determines which LightRAG query mode is used to generate the respond for the query. The supported prefixes include:
84
 
85
- ```
86
- /local
87
- /global
88
- /hybrid
89
- /naive
90
- /mix
91
- /bypass
92
  ```
93
 
94
- For example, chat message "/mix 唐僧有几个徒弟" will trigger a mix mode query for LighRAG. A chat message without query prefix will trigger a hybrid mode query by default。
95
 
96
- "/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 LightRAG query results. (If you are using Open WebUI as front end, you can just switch the model to a normal LLM instead of using /bypass prefix)
 
 
 
 
 
 
97
 
98
- #### Connect Open WebUI to LightRAG
99
 
100
- After starting the lightrag-server, you can add an Ollama-type connection in the Open WebUI admin pannel. And then a model named lightrag:latest will appear in Open WebUI's model management interface. Users can then send queries to LightRAG through the chat interface.
101
 
102
  ## Configuration
103
 
@@ -378,7 +386,7 @@ curl -X DELETE "http://localhost:9621/documents"
378
 
379
  #### GET /api/version
380
 
381
- Get Ollama version information
382
 
383
  ```bash
384
  curl http://localhost:9621/api/version
@@ -386,7 +394,7 @@ curl http://localhost:9621/api/version
386
 
387
  #### GET /api/tags
388
 
389
- Get Ollama available models
390
 
391
  ```bash
392
  curl http://localhost:9621/api/tags
@@ -394,7 +402,7 @@ curl http://localhost:9621/api/tags
394
 
395
  #### POST /api/chat
396
 
397
- Handle chat completion requests
398
 
399
  ```shell
400
  curl -N -X POST http://localhost:9621/api/chat -H "Content-Type: application/json" -d \
@@ -403,6 +411,10 @@ curl -N -X POST http://localhost:9621/api/chat -H "Content-Type: application/jso
403
 
404
  > For more information about Ollama API pls. visit : [Ollama API documentation](https://github.com/ollama/ollama/blob/main/docs/api.md)
405
 
 
 
 
 
406
  ### Utility Endpoints
407
 
408
  #### GET /health
@@ -412,7 +424,35 @@ Check server health and configuration.
412
  curl "http://localhost:9621/health"
413
  ```
414
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
415
  ## Development
 
416
  Contribute to the project: [Guide](contributor-readme.MD)
417
 
418
  ### Running in Development Mode
@@ -471,33 +511,3 @@ This intelligent caching mechanism:
471
  - This optimization significantly reduces startup time for subsequent runs
472
  - The working directory (`--working-dir`) stores the vectorized documents database
473
 
474
- ## Install Lightrag as a Linux Service
475
-
476
- Create a your service file `lightrag.sevice` from the sample file : `lightrag.sevice.example`. Modified the WorkingDirectoryand EexecStart in the service file:
477
-
478
- ```text
479
- Description=LightRAG Ollama Service
480
- WorkingDirectory=<lightrag installed directory>
481
- ExecStart=<lightrag installed directory>/lightrag/api/lightrag-api
482
- ```
483
-
484
- Modify your service startup script: `lightrag-api`. Change you python virtual environment activation command as needed:
485
-
486
- ```shell
487
- #!/bin/bash
488
-
489
- # your python virtual environment activation
490
- source /home/netman/lightrag-xyj/venv/bin/activate
491
- # start lightrag api server
492
- lightrag-server
493
- ```
494
-
495
- Install LightRAG service. If your system is Ubuntu, the following commands will work:
496
-
497
- ```shell
498
- sudo cp lightrag.service /etc/systemd/system/
499
- sudo systemctl daemon-reload
500
- sudo systemctl start lightrag.service
501
- sudo systemctl status lightrag.service
502
- sudo systemctl enable lightrag.service
503
- ```
 
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
 
81
+ ```text
82
+ Description=LightRAG Ollama Service
83
+ WorkingDirectory=<lightrag installed directory>
84
+ ExecStart=<lightrag installed directory>/lightrag/api/lightrag-api
85
+ ```
86
 
87
+ Modify your service startup script: `lightrag-api`. Change you python virtual environment activation command as needed:
88
 
89
+ ```shell
90
+ #!/bin/bash
91
+
92
+ # your python virtual environment activation
93
+ source /home/netman/lightrag-xyj/venv/bin/activate
94
+ # start lightrag api server
95
+ lightrag-server
96
  ```
97
 
98
+ Install LightRAG service. If your system is Ubuntu, the following commands will work:
99
 
100
+ ```shell
101
+ sudo cp lightrag.service /etc/systemd/system/
102
+ sudo systemctl daemon-reload
103
+ sudo systemctl start lightrag.service
104
+ sudo systemctl status lightrag.service
105
+ sudo systemctl enable lightrag.service
106
+ ```
107
 
 
108
 
 
109
 
110
  ## Configuration
111
 
 
386
 
387
  #### GET /api/version
388
 
389
+ Get Ollama version information.
390
 
391
  ```bash
392
  curl http://localhost:9621/api/version
 
394
 
395
  #### GET /api/tags
396
 
397
+ Get Ollama available models.
398
 
399
  ```bash
400
  curl http://localhost:9621/api/tags
 
402
 
403
  #### POST /api/chat
404
 
405
+ Handle chat completion requests. Routes user queries through LightRAG by selecting query mode based on query prefix. Detects and forwards OpenWebUI session-related requests (for meta data generation task) directly to underlying LLM.
406
 
407
  ```shell
408
  curl -N -X POST http://localhost:9621/api/chat -H "Content-Type: application/json" -d \
 
411
 
412
  > For more information about Ollama API pls. visit : [Ollama API documentation](https://github.com/ollama/ollama/blob/main/docs/api.md)
413
 
414
+ #### POST /api/generate
415
+
416
+ Handle generate completion requests. For compatibility purpose, the request is not processed by LightRAG, and will be handled by underlying LLM model.
417
+
418
  ### Utility Endpoints
419
 
420
  #### GET /health
 
424
  curl "http://localhost:9621/health"
425
  ```
426
 
427
+ ## Ollama Emulation
428
+
429
+ We provide an Ollama-compatible interfaces for LightRAG, aiming to emulate LightRAG as an Ollama chat model. This allows AI chat frontends supporting Ollama, such as Open WebUI, to access LightRAG easily.
430
+
431
+ ### Connect Open WebUI to LightRAG
432
+
433
+ After starting the lightrag-server, you can add an Ollama-type connection in the Open WebUI admin pannel. And then a model named lightrag:latest will appear in Open WebUI's model management interface. Users can then send queries to LightRAG through the chat interface. You'd better install LightRAG as service for this use case.
434
+
435
+ Open WebUI's use LLM to do the session title and session keyword generation task. So the Ollama chat chat completion API detects and forwards OpenWebUI session-related requests directly to underlying LLM.
436
+
437
+ ### Choose Query mode in chat
438
+
439
+ A query prefix in the query string can determines which LightRAG query mode is used to generate the respond for the query. The supported prefixes include:
440
+
441
+ ```
442
+ /local
443
+ /global
444
+ /hybrid
445
+ /naive
446
+ /mix
447
+ /bypass
448
+ ```
449
+
450
+ For example, chat message "/mix 唐僧有几个徒弟" will trigger a mix mode query for LighRAG. A chat message without query prefix will trigger a hybrid mode query by default。
451
+
452
+ "/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.
453
+
454
  ## Development
455
+
456
  Contribute to the project: [Guide](contributor-readme.MD)
457
 
458
  ### Running in Development Mode
 
511
  - This optimization significantly reduces startup time for subsequent runs
512
  - The working directory (`--working-dir`) stores the vectorized documents database
513