-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathask.py
More file actions
32 lines (25 loc) · 1.1 KB
/
Copy pathask.py
File metadata and controls
32 lines (25 loc) · 1.1 KB
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
import os
from dotenv import load_dotenv
from langchain_community.vectorstores import FAISS
from langchain_google_genai import GoogleGenerativeAIEmbeddings, ChatGoogleGenerativeAI
from langchain_classic.chains import RetrievalQA
load_dotenv()
def main():
"""Terminal Q&A loop for document interaction."""
embeddings = GoogleGenerativeAIEmbeddings(model="models/text-embedding-004")
db_path = "./faiss_index"
if not os.path.exists(db_path):
print("Knowledge base empty.")
return
vector_db = FAISS.load_local(db_path, embeddings, allow_dangerous_deserialization=True)
llm = ChatGoogleGenerativeAI(model="gemini-3-flash-preview", temperature=0)
qa_chain = RetrievalQA.from_chain_type(llm=llm, retriever=vector_db.as_retriever(search_kwargs={"k": 3}))
print("\n=== mySearch Console ===")
while True:
try:
q = input("Query > ")
if q.lower() in ['exit', 'quit']: break
print(f"\nResponse: {qa_chain.invoke(q)['result']}\n")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__": main()