-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrag_pipeline.py
More file actions
36 lines (26 loc) · 825 Bytes
/
rag_pipeline.py
File metadata and controls
36 lines (26 loc) · 825 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
from langchain_community.vectorstores import Chroma
from langchain_community.embeddings import HuggingFaceEmbeddings
from langchain.chains import RetrievalQA
from langchain_groq import ChatGroq
from config import VECTOR_DB_DIR, EMBEDDING_MODEL, TOP_K, GROQ_API_KEY
def build_rag_pipeline():
embeddings = HuggingFaceEmbeddings(
model_name=EMBEDDING_MODEL
)
vectorstore = Chroma(
persist_directory=VECTOR_DB_DIR,
embedding_function=embeddings
)
retriever = vectorstore.as_retriever(
search_kwargs={"k": TOP_K}
)
llm = ChatGroq(
groq_api_key=GROQ_API_KEY,
model_name="llama3-8b-8192"
)
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
retriever=retriever,
return_source_documents=True
)
return qa_chain