LLMs don't know your company's internal documents, and their knowledge has a cutoff date.
Without RAG, if you ask an LLM about your updated catalog, HR manual, or the status of a
specific contract, the model may make up the answer (hallucinate).
RAG solves this by connecting the LLM to a knowledge base that can be updated in real time.
Instead of "remembering" information from training, the model looks it up and reads it right before answering.
The result: precise answers about your data, with no retraining needed.
Indexing phase (offline):
Basic RAG works well, but production RAG uses additional techniques:
# Full RAG pipeline with LangChain + pgVector
from langchain_community.document_loaders import PyPDFLoader
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.vectorstores import PGVector
from langchain_anthropic import ChatAnthropic
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_core.output_parsers import StrOutputParser
# 1. Load and split
loader = PyPDFLoader("company_contract.pdf")
chunks = RecursiveCharacterTextSplitter(
chunk_size=1000, chunk_overlap=200
).split_documents(loader.load())
# 2. Create the vector store
vectorstore = PGVector.from_documents(
documents=chunks,
embedding=embeddings,
connection_string="postgresql://user:pass@localhost/db",
collection_name="contracts"
)
# 3. RAG chain
retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
llm = ChatAnthropic(model="claude-sonnet-4-6")
prompt = ChatPromptTemplate.from_template(
"Document context:\n{context}\n\nQuestion: {question}\n\nAnswer:"
)
chain = (
{"context": retriever, "question": RunnablePassthrough()}
| prompt | llm | StrOutputParser()
)
print(chain.invoke("What are the penalties for breach of contract?"))Carlos Montiel is an enterprise AI solutions architect with experience in LLMs, Agents, RAG, and orchestration across Guatemala and Latin America.
Contact Carlos Montiel