-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5_5_RAG.py
More file actions
37 lines (28 loc) · 886 Bytes
/
Copy path5_5_RAG.py
File metadata and controls
37 lines (28 loc) · 886 Bytes
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
35
36
37
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain.vectorstores import Chroma
from langchain.embeddings import HuggingFaceEmbeddings
from langchain.chains import RetrievalQA
from dotenv import load_dotenv
import os
load_dotenv()
chat = ChatGoogleGenerativeAI(
model="gemini-1.5-flash", # Or gemini-1.5-pro etc.
temperature=0.7,
google_api_key=os.getenv("GEMINI_API_KEY"), # pass key directly or rely on env
)
embeddings = HuggingFaceEmbeddings(
model_name="all-MiniLM-L6-v2",
)
db = Chroma(
persist_directory="embeddings_db", # Directory to store the embeddings
embedding_function=embeddings
)
retriever = db.as_retriever()
chain = RetrievalQA.from_chain_type(
llm=chat,
retriever=retriever,
chain_type="stuff"
)
question = "What do you know about Issac Newton?"
result = chain.run(question)
print("Result:", result)