update README.md

This commit is contained in:
LarFii
2024-10-15 19:55:30 +08:00
parent ea126a7108
commit 70baa4b572

View File

@@ -20,6 +20,9 @@ This repository hosts the code of LightRAG. The structure of this code is based
![请添加图片描述](https://i-blog.csdnimg.cn/direct/b2aaf634151b4706892693ffb43d9093.png) ![请添加图片描述](https://i-blog.csdnimg.cn/direct/b2aaf634151b4706892693ffb43d9093.png)
</div> </div>
## 🎉 News
- [x] [2024.10.15]🎯🎯📢📢LightRAG now supports Hugging Face models!
## Install ## Install
* Install from source * Install from source
@@ -35,17 +38,27 @@ pip install lightrag-hku
## Quick Start ## Quick Start
* Set OpenAI API key in environment: `export OPENAI_API_KEY="sk-...".` * Set OpenAI API key in environment if using OpenAI models: `export OPENAI_API_KEY="sk-...".`
* Download the demo text "A Christmas Carol by Charles Dickens" * Download the demo text "A Christmas Carol by Charles Dickens":
```bash ```bash
curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt
``` ```
Use the below python snippet: Use the below Python snippet to initialize LightRAG and perform queries:
```python ```python
from lightrag import LightRAG, QueryParam from lightrag import LightRAG, QueryParam
from lightrag.llm import gpt_4o_mini_complete, gpt_4o_complete
rag = LightRAG(working_dir="./dickens") WORKING_DIR = "./dickens"
if not os.path.exists(WORKING_DIR):
os.mkdir(WORKING_DIR)
rag = LightRAG(
working_dir=WORKING_DIR,
llm_model_func=gpt_4o_mini_complete # Use gpt_4o_mini_complete LLM model
# llm_model_func=gpt_4o_complete # Optionally, use a stronger model
)
with open("./book.txt") as f: with open("./book.txt") as f:
rag.insert(f.read()) rag.insert(f.read())
@@ -62,13 +75,31 @@ print(rag.query("What are the top themes in this story?", param=QueryParam(mode=
# Perform hybrid search # Perform hybrid search
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid"))) print(rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid")))
``` ```
Batch Insert ### Using Hugging Face Models
If you want to use Hugging Face models, you only need to set LightRAG as follows:
```python ```python
from lightrag.llm import hf_model_complete, hf_embedding
from transformers import AutoModel, AutoTokenizer
# Initialize LightRAG with Hugging Face model
rag = LightRAG(
working_dir=WORKING_DIR,
llm_model_func=hf_model_complete, # Use Hugging Face complete model for text generation
llm_model_name='meta-llama/Llama-3.1-8B-Instruct', # Model name from Hugging Face
embedding_func=hf_embedding, # Use Hugging Face embedding function
tokenizer=AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2"),
embed_model=AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
)
```
### Batch Insert
```python
# Batch Insert: Insert multiple texts at once
rag.insert(["TEXT1", "TEXT2",...]) rag.insert(["TEXT1", "TEXT2",...])
``` ```
Incremental Insert ### Incremental Insert
```python ```python
# Incremental Insert: Insert new documents into an existing LightRAG instance
rag = LightRAG(working_dir="./dickens") rag = LightRAG(working_dir="./dickens")
with open("./newText.txt") as f: with open("./newText.txt") as f: