Spaces:
Sleeping
Sleeping
| import os | |
| from tqdm import tqdm | |
| from langchain_community.vectorstores import FAISS | |
| from langchain_google_genai import GoogleGenerativeAIEmbeddings | |
| # Import từ helpers | |
| from helpers import ( | |
| list_docx_files, # Lấy danh sách file .docx | |
| get_splits, # Xử lý file docx thành splits | |
| get_json_splits_only, # Xử lý file JSON (FAQ) | |
| get_urls_splits, # Xử lý dữ liệu từ web | |
| ) | |
| def get_vectorstore(): | |
| ### Xử lý tất cả các tài liệu và nhét vào database | |
| folder_path = "syllabus_nct_word_format/" | |
| docx_files = list_docx_files(folder_path) | |
| all_splits = [] # Khởi tạo danh sách lưu kết quả | |
| for i, file_path in enumerate(tqdm(docx_files, desc="Đang xử lý", unit="file")): | |
| output_json_path = f"output_{i}.json" | |
| splits = get_splits(file_path, output_json_path) | |
| all_splits += splits | |
| # Xử lý FAQ | |
| FAQ_path = "syllabus_nct_word_format/FAQ.json" | |
| FAQ_splits = get_json_splits_only(FAQ_path) | |
| all_splits += FAQ_splits | |
| # Lưu vào vectorstore với nhúng từ Google GenAI | |
| embedding = GoogleGenerativeAIEmbeddings(model="models/text-embedding-004") | |
| vectorstore = FAISS.from_documents(documents=all_splits, embedding=embedding) | |
| return vectorstore | |