Skip to content

Commit 83967f9

Browse files
committed
Enhance: Switched model to llama3.2, Improved RAG Capabilites for multi column text in document
1 parent 682697f commit 83967f9

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

dependencies.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ollama
44
chromadb
55
langchain
66
langchain-community
7-
pypdf
87
langchain-text-splitters
9-
langchain-ollama
8+
langchain-ollama
9+
pymupdf
10+
protobuf==3.20.3

main.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
# Required Libs
2-
from langchain_community.document_loaders import PyPDFLoader
2+
from langchain_community.document_loaders import PyMuPDFLoader
33
from langchain_text_splitters import RecursiveCharacterTextSplitter
44
from langchain_community.vectorstores import Chroma
55
from langchain_ollama import OllamaEmbeddings
66
import ollama
77

88
# Load and Chunk the Data
99
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")
1111
pages = loader.load()
1212

1313
# 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)
1515
chunks = text_splitter.split_documents(pages)
1616

1717
# Embed and Store in Vector DB
@@ -21,7 +21,7 @@
2121
vectorstore = Chroma.from_documents(documents=chunks, embedding=embeddings)
2222

2323
# 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})
2525

2626
print("\n\nHi there! (Press Ctrl+C to exit)")
2727

@@ -36,16 +36,19 @@
3636

3737
# Construct the Prompt with Attention
3838
# 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."
4043
4144
Context:
4245
{context_block}
4346
4447
Question: {user_input}
4548
Answer:"""
4649

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=[
4952
{'role': 'user', 'content': rag_prompt}
5053
])
5154

run.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/bin/bash
2-
31
# Variables
42
PKG_MGR="pip"
53
FILE="dependencies.txt"
@@ -73,9 +71,23 @@ else
7371
echo "[OK] Ollama engine is already installed."
7472
fi
7573

74+
# Check for PyMuPDF
75+
if ! python3 -c "import pymupdf" &> /dev/null; then
76+
echo "[WARNING] Python cannot find 'pymupdf' library. Forcing strict inline installation..."
77+
python3 -m pip install pymupdf
78+
79+
if [ $? -ne 0 ]; then
80+
echo "[ERROR] Could not force-install Python pymupdf library."
81+
exit 1
82+
fi
83+
echo "[OK] 'pymupdf' bound to current Python environment."
84+
else
85+
echo "[OK] Python recognizes 'pymupdf'."
86+
fi
87+
7688
# Required Models for RAG
77-
echo "[INFO] Verifying AI models (TinyLlama & Nomic)..."
78-
ollama pull tinyllama
89+
echo "[INFO] Verifying AI models (Llama3.2 & Nomic)..."
90+
ollama pull llama3.2
7991
ollama pull nomic-embed-text
8092
echo "[OK] All models are ready."
8193

0 commit comments

Comments
 (0)