File size: 840 Bytes
ed084d7 |
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 |
"""
BƯỚC 4: VECTORSTORE (FAISS in-memory)
"""
from langchain_community.vectorstores import FAISS
from embeddings import get_embeddings
def build_vectorstore(chunks):
print(">>> Initialising embedding model for FAISS index ...")
embeddings = get_embeddings()
print(f">>> Building FAISS index from {len(chunks)} chunks ...")
vs = FAISS.from_documents(chunks, embeddings)
print(">>> FAISS index built.\n")
return vs
if __name__ == "__main__":
from load_documents import load_documents
from split_documents import split_documents
docs = load_documents()
chunks = split_documents(docs)
vs = build_vectorstore(chunks)
res = vs.similarity_search(
"Fristen für die Prüfungsanmeldung im Bachelorstudium", k=3
)
for r in res:
print(r.page_content[:200], r.metadata)
|