-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinsert_docs.py
More file actions
25 lines (20 loc) · 785 Bytes
/
insert_docs.py
File metadata and controls
25 lines (20 loc) · 785 Bytes
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
import asyncio
from main import initialize_rag
async def insert_documents():
rag = await initialize_rag()
# Insertion d'un fichier texte
with open("data/documents/greenpower_products.txt", "r", encoding="utf-8") as f:
content = f.read()
await rag.ainsert(content)
print("Document indexé - knowledge graph construit")
# Insertion de plusieurs fichiers
import os
doc_dir = "data/documents/"
for filename in os.listdir(doc_dir):
if filename.endswith(".txt"):
with open(os.path.join(doc_dir, filename), "r", encoding="utf-8") as f:
content = f.read()
await rag.ainsert(content)
print(f"Indexé : {filename}")
if __name__ == "__main__":
asyncio.run(insert_documents())