-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIndexing.py
More file actions
52 lines (40 loc) · 1.54 KB
/
Copy pathIndexing.py
File metadata and controls
52 lines (40 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import asyncio
import os
from ylightRag.ylightrag import LightRAG
from ylightRag.yllm.openai import gpt_4o_mini_complete, openai_embed
from ylightRag.ykg.shared_storage import initialize_pipeline_status
from ylightRag.yutils import EmbeddingFunc
Document_dir = "Documents"
"""Directory where Documents for indexing for query store"""
working_dir = "Cache"
"""Directory where cache and temporary files are stored."""
if not os.path.exists(working_dir):
os.mkdir(working_dir)
async def main():
if os.path.exists(Document_dir):
print(f"Directory {Document_dir} exist.")
rag = LightRAG(llm_model_func=gpt_4o_mini_complete,
embedding_func=EmbeddingFunc(
embedding_dim=1536,
max_token_size=8192,
func=openai_embed
),
working_dir=working_dir)
await rag.initialize_storages()
await initialize_pipeline_status()
# Now indexing
def find_txt_files(root_path):
txt_files = []
for root, dirs, files in os.walk(root_path):
for file in files:
if file.endswith(".txt"):
txt_files.append(os.path.join(root, file))
return txt_files
WEEK_LIST = find_txt_files(Document_dir)
for WEEK in WEEK_LIST:
id = WEEK_LIST.index(WEEK)
print(f"{id}/{len(WEEK_LIST)}")
with open(WEEK,'r',encoding="utf-8") as f:
await rag.ainsert(f.read())
if __name__ == "__main__":
asyncio.run(main())