| """ | |
| 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) | |