File size: 1,282 Bytes
fd22419
 
 
 
 
 
 
 
 
 
 
 
32e14d1
fd22419
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32e14d1
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
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