|
1 | 1 | # Required Libs |
2 | | -from langchain_community.document_loaders import PyPDFLoader |
| 2 | +from langchain_community.document_loaders import PyMuPDFLoader |
3 | 3 | from langchain_text_splitters import RecursiveCharacterTextSplitter |
4 | 4 | from langchain_community.vectorstores import Chroma |
5 | 5 | from langchain_ollama import OllamaEmbeddings |
6 | 6 | import ollama |
7 | 7 |
|
8 | 8 | # Load and Chunk the Data |
9 | 9 | print("[INFO] Reading HR Policy PDF...") |
10 | | -loader = PyPDFLoader("rag_source/nasscom-hr-manual-2016.pdf") |
| 10 | +loader = PyMuPDFLoader("rag_source/nasscom-hr-manual-2016.pdf") |
11 | 11 | pages = loader.load() |
12 | 12 |
|
13 | 13 | # Break the dense PDF into small, 500-character chunks |
14 | | -text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=50) |
| 14 | +text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000, chunk_overlap=150) |
15 | 15 | chunks = text_splitter.split_documents(pages) |
16 | 16 |
|
17 | 17 | # Embed and Store in Vector DB |
|
21 | 21 | vectorstore = Chroma.from_documents(documents=chunks, embedding=embeddings) |
22 | 22 |
|
23 | 23 | # Retriever to fetch the top 3 most relevant chunks |
24 | | -retriever = vectorstore.as_retriever(search_kwargs={"k": 3}) |
| 24 | +retriever = vectorstore.as_retriever(search_kwargs={"k": 2}) |
25 | 25 |
|
26 | 26 | print("\n\nHi there! (Press Ctrl+C to exit)") |
27 | 27 |
|
|
36 | 36 |
|
37 | 37 | # Construct the Prompt with Attention |
38 | 38 | # Custom RAG Prompt to only use resources from the rag source |
39 | | - rag_prompt = f"""You are a helpful HR assistant. Answer the user's question using ONLY the context provided below. If the answer is not in the context, say you don't know. |
| 39 | + rag_prompt = f"""You are a precise HR assistant. |
| 40 | + Read the provided Context carefully. You must answer the user's question using ONLY the facts found in the Context below. |
| 41 | + |
| 42 | + If the Context does not contain the exact answer, simply reply: "I cannot find the answer to that in the current policy." |
40 | 43 | |
41 | 44 | Context: |
42 | 45 | {context_block} |
43 | 46 | |
44 | 47 | Question: {user_input} |
45 | 48 | Answer:""" |
46 | 49 |
|
47 | | - # Generate the answer using TinyLlama |
48 | | - response = ollama.chat(model='tinyllama', messages=[ |
| 50 | + # Generate the answer using Llama 3.2 |
| 51 | + response = ollama.chat(model='llama3.2', messages=[ |
49 | 52 | {'role': 'user', 'content': rag_prompt} |
50 | 53 | ]) |
51 | 54 |
|
|
0 commit comments