LarFii
commited on
Commit
·
d76f618
1
Parent(s):
4460ba5
update README.md
Browse files
README.md
CHANGED
@@ -20,6 +20,9 @@ This repository hosts the code of LightRAG. The structure of this code is based
|
|
20 |

|
21 |
</div>
|
22 |
|
|
|
|
|
|
|
23 |
## Install
|
24 |
|
25 |
* Install from source
|
@@ -35,17 +38,27 @@ pip install lightrag-hku
|
|
35 |
|
36 |
## Quick Start
|
37 |
|
38 |
-
* Set OpenAI API key in environment: `export OPENAI_API_KEY="sk-...".`
|
39 |
-
* Download the demo text "A Christmas Carol by Charles Dickens"
|
40 |
```bash
|
41 |
curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt
|
42 |
```
|
43 |
-
Use the below
|
44 |
|
45 |
```python
|
46 |
from lightrag import LightRAG, QueryParam
|
|
|
47 |
|
48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
with open("./book.txt") as f:
|
51 |
rag.insert(f.read())
|
@@ -62,13 +75,31 @@ print(rag.query("What are the top themes in this story?", param=QueryParam(mode=
|
|
62 |
# Perform hybrid search
|
63 |
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid")))
|
64 |
```
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
```python
|
|
|
67 |
rag.insert(["TEXT1", "TEXT2",...])
|
68 |
```
|
69 |
-
Incremental Insert
|
70 |
|
71 |
```python
|
|
|
72 |
rag = LightRAG(working_dir="./dickens")
|
73 |
|
74 |
with open("./newText.txt") as f:
|
|
|
20 |

|
21 |
</div>
|
22 |
|
23 |
+
## 🎉 News
|
24 |
+
- [x] [2024.10.15]🎯🎯📢📢LightRAG now supports Hugging Face models!
|
25 |
+
|
26 |
## Install
|
27 |
|
28 |
* Install from source
|
|
|
38 |
|
39 |
## Quick Start
|
40 |
|
41 |
+
* Set OpenAI API key in environment if using OpenAI models: `export OPENAI_API_KEY="sk-...".`
|
42 |
+
* Download the demo text "A Christmas Carol by Charles Dickens":
|
43 |
```bash
|
44 |
curl https://raw.githubusercontent.com/gusye1234/nano-graphrag/main/tests/mock_data.txt > ./book.txt
|
45 |
```
|
46 |
+
Use the below Python snippet to initialize LightRAG and perform queries:
|
47 |
|
48 |
```python
|
49 |
from lightrag import LightRAG, QueryParam
|
50 |
+
from lightrag.llm import gpt_4o_mini_complete, gpt_4o_complete
|
51 |
|
52 |
+
WORKING_DIR = "./dickens"
|
53 |
+
|
54 |
+
if not os.path.exists(WORKING_DIR):
|
55 |
+
os.mkdir(WORKING_DIR)
|
56 |
+
|
57 |
+
rag = LightRAG(
|
58 |
+
working_dir=WORKING_DIR,
|
59 |
+
llm_model_func=gpt_4o_mini_complete # Use gpt_4o_mini_complete LLM model
|
60 |
+
# llm_model_func=gpt_4o_complete # Optionally, use a stronger model
|
61 |
+
)
|
62 |
|
63 |
with open("./book.txt") as f:
|
64 |
rag.insert(f.read())
|
|
|
75 |
# Perform hybrid search
|
76 |
print(rag.query("What are the top themes in this story?", param=QueryParam(mode="hybrid")))
|
77 |
```
|
78 |
+
### Using Hugging Face Models
|
79 |
+
If you want to use Hugging Face models, you only need to set LightRAG as follows:
|
80 |
+
```python
|
81 |
+
from lightrag.llm import hf_model_complete, hf_embedding
|
82 |
+
from transformers import AutoModel, AutoTokenizer
|
83 |
+
|
84 |
+
# Initialize LightRAG with Hugging Face model
|
85 |
+
rag = LightRAG(
|
86 |
+
working_dir=WORKING_DIR,
|
87 |
+
llm_model_func=hf_model_complete, # Use Hugging Face complete model for text generation
|
88 |
+
llm_model_name='meta-llama/Llama-3.1-8B-Instruct', # Model name from Hugging Face
|
89 |
+
embedding_func=hf_embedding, # Use Hugging Face embedding function
|
90 |
+
tokenizer=AutoTokenizer.from_pretrained("sentence-transformers/all-MiniLM-L6-v2"),
|
91 |
+
embed_model=AutoModel.from_pretrained("sentence-transformers/all-MiniLM-L6-v2")
|
92 |
+
)
|
93 |
+
```
|
94 |
+
### Batch Insert
|
95 |
```python
|
96 |
+
# Batch Insert: Insert multiple texts at once
|
97 |
rag.insert(["TEXT1", "TEXT2",...])
|
98 |
```
|
99 |
+
### Incremental Insert
|
100 |
|
101 |
```python
|
102 |
+
# Incremental Insert: Insert new documents into an existing LightRAG instance
|
103 |
rag = LightRAG(working_dir="./dickens")
|
104 |
|
105 |
with open("./newText.txt") as f:
|