update README.md
This commit is contained in:
43
README.md
43
README.md
@@ -20,6 +20,9 @@ This repository hosts the code of LightRAG. The structure of this code is based
|
||||

|
||||
</div>
|
||||
|
||||
## 🎉 News
|
||||
- [x] [2024.10.15]🎯🎯📢📢LightRAG now supports Hugging Face models!
|
||||
|
||||
## Install
|
||||
|
||||
* Install from source
|
||||
@@ -35,17 +38,27 @@ pip install lightrag-hku
|
||||
|
||||
## Quick Start
|
||||
|
||||
* Set OpenAI API key in environment: `export OPENAI_API_KEY="sk-...".`
|
||||
* Download the demo text "A Christmas Carol by Charles Dickens"
|
||||
* 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":
|
||||
```bash
|
||||
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
|
||||
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:
|
||||
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
|
||||
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
|
||||
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",...])
|
||||
```
|
||||
Incremental Insert
|
||||
### Incremental Insert
|
||||
|
||||
```python
|
||||
# Incremental Insert: Insert new documents into an existing LightRAG instance
|
||||
rag = LightRAG(working_dir="./dickens")
|
||||
|
||||
with open("./newText.txt") as f:
|
||||
|
Reference in New Issue
Block a user