Fix linting of README

This commit is contained in:
yangdx
2025-03-25 16:23:15 +08:00
parent 9b2c31f30e
commit ac703dc448
2 changed files with 64 additions and 90 deletions

View File

@@ -169,6 +169,10 @@ class QueryParam:
> top_k的默认值可以通过环境变量TOP_K更改。
### LLM and Embedding注入
LightRAG 需要利用LLM和Embeding模型来完成文档索引和知识库查询工作。在初始化LightRAG的时候需要把阶段需要把LLM和Embedding的操作函数注入到对象中
<details>
<summary> <b>使用类OpenAI的API</b> </summary>
@@ -245,9 +249,6 @@ rag = LightRAG(
<details>
<summary> <b>使用Ollama模型</b> </summary>
### 概述
如果您想使用Ollama模型您需要拉取计划使用的模型和嵌入模型例如`nomic-embed-text`
然后您只需要按如下方式设置LightRAG
@@ -270,11 +271,11 @@ rag = LightRAG(
)
```
### 增加上下文大小
* **增加上下文大小**
为了使LightRAG正常工作上下文应至少为32k令牌。默认情况下Ollama模型的上下文大小为8k。您可以通过以下两种方式之一实现这一点
#### 在Modelfile中增加`num_ctx`参数
* **在Modelfile中增加`num_ctx`参数**
1. 拉取模型:
@@ -300,7 +301,7 @@ PARAMETER num_ctx 32768
ollama create -f Modelfile qwen2m
```
#### 通过Ollama API设置`num_ctx`
* **通过Ollama API设置`num_ctx`**
您可以使用`llm_model_kwargs`参数配置ollama
@@ -322,7 +323,7 @@ rag = LightRAG(
)
```
#### 低RAM GPU
* **低RAM GPU**
为了在低RAM GPU上运行此实验您应该选择小型模型并调整上下文窗口增加上下文会增加内存消耗。例如在6Gb RAM的改装挖矿GPU上运行这个ollama示例需要将上下文大小设置为26k同时使用`gemma2:2b`。它能够在`book.txt`中找到197个实体和19个关系。
@@ -330,13 +331,12 @@ rag = LightRAG(
<details>
<summary> <b>LlamaIndex</b> </summary>
LightRAG支持与LlamaIndex集成
LightRAG支持与LlamaIndex集成 (`llm/llama_index_impl.py`):
1. **LlamaIndex** (`llm/llama_index_impl.py`):
- 通过LlamaIndex与OpenAI和其他提供商集成
- 详细设置和示例请参见[LlamaIndex文档](lightrag/llm/Readme.md)
- 通过LlamaIndex与OpenAI和其他提供商集成
- 详细设置和示例请参见[LlamaIndex文档](lightrag/llm/Readme.md)
### 使用示例
**使用示例:**
```python
# 使用LlamaIndex直接访问OpenAI
@@ -398,15 +398,15 @@ if __name__ == "__main__":
main()
```
#### 详细文档和示例,请参见:
**详细文档和示例,请参见:**
- [LlamaIndex文档](lightrag/llm/Readme.md)
- [直接OpenAI示例](examples/lightrag_llamaindex_direct_demo.py)
- [LiteLLM代理示例](examples/lightrag_llamaindex_litellm_demo.py)
</details>
<details>
<summary> <b>对话历史支持</b> </summary>
### 对话历史
LightRAG现在通过对话历史功能支持多轮对话。以下是使用方法
@@ -432,10 +432,7 @@ response = rag.query(
)
```
</details>
<details>
<summary> <b>自定义提示支持</b> </summary>
### 自定义提示词
LightRAG现在支持自定义提示以便对系统行为进行精细控制。以下是使用方法
@@ -473,14 +470,11 @@ response_custom = rag.query(
print(response_custom)
```
</details>
<details>
<summary> <b>独立关键词提取</b> </summary>
### 关键词提取
我们引入了新函数`query_with_separate_keyword_extraction`来增强关键词提取功能。该函数将关键词提取过程与用户提示分开,专注于查询以提高提取关键词的相关性。
##### 工作原理
* 工作原理
该函数将输入分为两部分:
@@ -489,7 +483,7 @@ print(response_custom)
然后仅对`用户查询`执行关键词提取。这种分离确保提取过程是集中和相关的,不受`提示`中任何额外语言的影响。它还允许`提示`纯粹用于响应格式化,保持用户原始问题的意图和清晰度。
##### 使用示例
* 使用示例
这个`示例`展示了如何为教育内容定制函数,专注于为高年级学生提供详细解释。
@@ -501,10 +495,7 @@ rag.query_with_separate_keyword_extraction(
)
```
</details>
<details>
<summary> <b>插入自定义KG</b> </summary>
### 插入自定义知识
```python
custom_kg = {
@@ -565,8 +556,6 @@ custom_kg = {
rag.insert_custom_kg(custom_kg)
```
</details>
## 插入
#### 基本插入
@@ -877,13 +866,13 @@ updated_relation = rag.edit_relation("Google", "Google Mail", {
## 数据导出功能
## 概述
### 概述
LightRAG允许您以各种格式导出知识图谱数据用于分析、共享和备份目的。系统支持导出实体、关系和关系数据。
## 导出功能
### 导出功能
### 基本用法
#### 基本用法
```python
# 基本CSV导出默认格式
@@ -893,7 +882,7 @@ rag.export_data("knowledge_graph.csv")
rag.export_data("output.xlsx", file_format="excel")
```
### 支持的不同文件格式
#### 支持的不同文件格式
```python
# 以CSV格式导出数据
@@ -909,7 +898,7 @@ rag.export_data("graph_data.md", file_format="md")
rag.export_data("graph_data.txt", file_format="txt")
```
## 附加选项
#### 附加选项
在导出中包含向量嵌入(可选):
@@ -917,7 +906,7 @@ rag.export_data("graph_data.txt", file_format="txt")
rag.export_data("complete_data.csv", include_vector_data=True)
```
## 导出数据包括
### 导出数据包括
所有导出包括:
@@ -1079,13 +1068,11 @@ API包括全面的错误处理
</details>
## API
## LightRAG API
LightRag可以安装API支持以提供Fast api接口来执行数据上传和索引/Rag操作/重新扫描输入文件夹等。
LightRAG服务器旨在提供Web UI和API支持。**有关LightRAG服务器的更多信息请参阅[LightRAG服务器](./lightrag/api/README.md)。**
[LightRag API](lightrag/api/README.md)
## 图形可视化
## 知识图谱可视化
LightRAG服务器提供全面的知识图谱可视化功能。它支持各种重力布局、节点查询、子图过滤等。**有关LightRAG服务器的更多信息请参阅[LightRAG服务器](./lightrag/api/README.md)。**

View File

@@ -199,6 +199,10 @@ class QueryParam:
> default value of Top_k can be change by environment variables TOP_K.
### LLM and Embedding Injection
LightRAG requires the utilization of LLM and Embedding models to accomplish document indexing and querying tasks. During the initialization phase, it is necessary to inject the invocation methods of the relevant models into LightRAG
<details>
<summary> <b>Using Open AI-like APIs</b> </summary>
@@ -275,8 +279,7 @@ rag = LightRAG(
<details>
<summary> <b>Using Ollama Models</b> </summary>
### Overview
**Overview**
If you want to use Ollama models, you need to pull model you plan to use and embedding model, for example `nomic-embed-text`.
@@ -300,11 +303,11 @@ rag = LightRAG(
)
```
### Increasing context size
* **Increasing context size**
In order for LightRAG to work context should be at least 32k tokens. By default Ollama models have context size of 8k. You can achieve this using one of two ways:
#### Increasing the `num_ctx` parameter in Modelfile.
* **Increasing the `num_ctx` parameter in Modelfile**
1. Pull the model:
@@ -330,7 +333,7 @@ PARAMETER num_ctx 32768
ollama create -f Modelfile qwen2m
```
#### Setup `num_ctx` via Ollama API.
* **Setup `num_ctx` via Ollama API**
Tiy can use `llm_model_kwargs` param to configure ollama:
@@ -352,7 +355,7 @@ rag = LightRAG(
)
```
#### Low RAM GPUs
* **Low RAM GPUs**
In order to run this experiment on low RAM GPU you should select small model and tune context window (increasing context increase memory consumption). For example, running this ollama example on repurposed mining GPU with 6Gb of RAM required to set context size to 26k while using `gemma2:2b`. It was able to find 197 entities and 19 relations on `book.txt`.
@@ -360,13 +363,12 @@ In order to run this experiment on low RAM GPU you should select small model and
<details>
<summary> <b>LlamaIndex</b> </summary>
LightRAG supports integration with LlamaIndex.
LightRAG supports integration with LlamaIndex (`llm/llama_index_impl.py`):
1. **LlamaIndex** (`llm/llama_index_impl.py`):
- Integrates with OpenAI and other providers through LlamaIndex
- See [LlamaIndex Documentation](lightrag/llm/Readme.md) for detailed setup and examples
- Integrates with OpenAI and other providers through LlamaIndex
- See [LlamaIndex Documentation](lightrag/llm/Readme.md) for detailed setup and examples
### Example Usage
**Example Usage**
```python
# Using LlamaIndex with direct OpenAI access
@@ -428,15 +430,14 @@ if __name__ == "__main__":
main()
```
#### For detailed documentation and examples, see:
**For detailed documentation and examples, see:**
- [LlamaIndex Documentation](lightrag/llm/Readme.md)
- [Direct OpenAI Example](examples/lightrag_llamaindex_direct_demo.py)
- [LiteLLM Proxy Example](examples/lightrag_llamaindex_litellm_demo.py)
</details>
<details>
<summary> <b>Conversation History Support</b> </summary>
### Conversation History Support
LightRAG now supports multi-turn dialogue through the conversation history feature. Here's how to use it:
@@ -462,10 +463,7 @@ response = rag.query(
)
```
</details>
<details>
<summary> <b>Custom Prompt Support</b> </summary>
### Custom Prompt Support
LightRAG now supports custom prompts for fine-tuned control over the system's behavior. Here's how to use it:
@@ -503,14 +501,11 @@ response_custom = rag.query(
print(response_custom)
```
</details>
<details>
<summary> <b>Separate Keyword Extraction</b> </summary>
### Separate Keyword Extraction
We've introduced a new function `query_with_separate_keyword_extraction` to enhance the keyword extraction capabilities. This function separates the keyword extraction process from the user's prompt, focusing solely on the query to improve the relevance of extracted keywords.
##### How It Works?
**How It Works?**
The function operates by dividing the input into two parts:
@@ -519,7 +514,7 @@ The function operates by dividing the input into two parts:
It then performs keyword extraction exclusively on the `user query`. This separation ensures that the extraction process is focused and relevant, unaffected by any additional language in the `prompt`. It also allows the `prompt` to serve purely for response formatting, maintaining the intent and clarity of the user's original question.
##### Usage Example
**Usage Example**
This `example` shows how to tailor the function for educational content, focusing on detailed explanations for older students.
@@ -531,10 +526,7 @@ rag.query_with_separate_keyword_extraction(
)
```
</details>
<details>
<summary> <b>Insert Custom KG</b> </summary>
### Insert Custom KG
```python
custom_kg = {
@@ -599,13 +591,16 @@ rag.insert_custom_kg(custom_kg)
## Insert
#### Basic Insert
<details>
<summary> <b> Basic Insert </b></summary>
```python
# Basic Insert
rag.insert("Text")
```
</details>
<details>
<summary> <b> Batch Insert </b></summary>
@@ -842,8 +837,7 @@ rag.delete_by_doc_id("doc_id")
LightRAG now supports comprehensive knowledge graph management capabilities, allowing you to create, edit, and delete entities and relationships within your knowledge graph.
<details>
<summary> <b>Create Entities and Relations</b> </summary>
### Create Entities and Relations
```python
# Create new entity
@@ -866,10 +860,7 @@ relation = rag.create_relation("Google", "Gmail", {
})
```
</details>
<details>
<summary> <b>Edit Entities and Relations</b> </summary>
### Edit Entities and Relations
```python
# Edit an existing entity
@@ -892,8 +883,6 @@ updated_relation = rag.edit_relation("Google", "Google Mail", {
})
```
</details>
All operations are available in both synchronous and asynchronous versions. The asynchronous versions have the prefix "a" (e.g., `acreate_entity`, `aedit_relation`).
#### Entity Operations
@@ -910,13 +899,13 @@ These operations maintain data consistency across both the graph database and ve
## Data Export Functions
## Overview
### Overview
LightRAG allows you to export your knowledge graph data in various formats for analysis, sharing, and backup purposes. The system supports exporting entities, relations, and relationship data.
## Export Functions
### Export Functions
### Basic Usage
#### Basic Usage
```python
# Basic CSV export (default format)
@@ -926,7 +915,7 @@ rag.export_data("knowledge_graph.csv")
rag.export_data("output.xlsx", file_format="excel")
```
### Different File Formats supported
#### Different File Formats supported
```python
#Export data in CSV format
@@ -941,14 +930,14 @@ rag.export_data("graph_data.md", file_format="md")
# Export data in Text
rag.export_data("graph_data.txt", file_format="txt")
```
## Additional Options
#### Additional Options
Include vector embeddings in the export (optional):
```python
rag.export_data("complete_data.csv", include_vector_data=True)
```
## Data Included in Export
### Data Included in Export
All exports include:
@@ -1111,11 +1100,9 @@ The API includes comprehensive error handling:
</details>
## API
## LightRAG API
LightRag can be installed with API support to serve a Fast api interface to perform data upload and indexing/Rag operations/Rescan of the input folder etc..
[LightRag API](lightrag/api/README.md)
The LightRAG Server is designed to provide Web UI and API support. **For more information about LightRAG Server, please refer to [LightRAG Server](./lightrag/api/README.md).**
## Graph Visualization