Vamshi2277/AI-Powered-Human-Rights-Intelligence
0
1from langchain_community.vectorstores import FAISS2from langchain_huggingface import HuggingFaceEmbeddings3import os4 5EMBEDDING_MODEL = "sentence-transformers/all-MiniLM-L6-v2"6 7 8def load_vectorstore():9 10 if not os.path.exists("rag_faiss_store"):11 12 return None13 14 embeddings = HuggingFaceEmbeddings(15 model_name=EMBEDDING_MODEL16 )17 18 db = FAISS.load_local(19 "rag_faiss_store",20 embeddings,21 allow_dangerous_deserialization=True22 )23 24 return db25 26 27def retrieve_legal_context(query):28 29 db = load_vectorstore()30 31 if db is None:32 33 return "No legal document uploaded yet."34 35 docs = db.similarity_search(query, k=4)36 37 context = "\n\n".join(38 [doc.page_content for doc in docs]39 )40 41 return context