inflearn logo

LLM·RAG in Practice — AI Agents Safely Connected to Internal Documents and Databases

We connect LLMs to internal documents and business databases, then use numbers to prove whether the answers are accurate, whether data leaks, and how much it costs. We run local models (Ollama) and PostgreSQL+pgvector with Docker and reproduce all 48 lessons without paid APIs, showing even the techniques that didn’t work exactly as measured.

1 learners are taking this course

Level Intermediate

Course period Unlimited

RAG
RAG
LLM
LLM
pgvector
pgvector
PostgreSQL
PostgreSQL
AI Agent
AI Agent
RAG
RAG
LLM
LLM
pgvector
pgvector
PostgreSQL
PostgreSQL
AI Agent
AI Agent

What you will gain after the course

  • Measure the accuracy and hallucination rates of an LLM alone, keyword search, and RAG using the same set of questions, then build your first 100-line RAG yourself.

  • Choose by comparing embedding models, chunking (length, overlap, and document structure), and metadata based on recall across 60 questions, and handle document updates and model replacements using zero-downtime procedures.

  • Read HNSW indexes, filtered searches, and execution plans in PostgreSQL+pgvector, and fix the pitfall where adding conditions yields zero results.

  • Use regression gate scores to decide whether to adopt or reject hybrid search, reranking, and query transformation, and analyze failures when they have no effect.

  • Create and validate a ground-truth answer set, separately measure the accuracy of retrieval, responses, and LLM judge graders, and automatically generate evaluation reports.

  • Use row-level security to block unauthorized documents, and evaluate prompt injection, privacy, output guardrails, and audit logs with a test set.

  • Place Text-to-SQL and tool-calling agents behind read-only accounts, time limits, and human approval, and use a checklist to verify cost, latency, caching, and failover paths.

If you’ve connected an LLM to internal documents and databases, can you quantify how accurate its answers are, whether it leaks data, and how much it costs?

We connect an LLM to internal documents and business databases, then prove with numbers whether its answers are correct, whether it leaks data, and how much it costs. We run a local model (Ollama) and PostgreSQL+pgvector in Docker, reproduce all 48 lessons without paid APIs, and show the techniques that didn’t work exactly as measured.

Every number in this course comes from an actual run, and many results turned out differently than expected. In the first lesson, we run the same set of questions through three approaches. Of the 20 questions whose answers are in the documents, the standalone LLM gets 1 right, keyword search gets 15, and RAG gets 16. But in Part 4, hybrid search actually lowers recall@1 from 0.95 to 0.87, reranking lowers it from 0.87 to 0.73, and query rewriting lowers it from 0.95 to 0.77. In Part 6, adding input validation and row-level security does not reduce attack success at all: it remains 2/20. And the blocking rules also block 6 correct answers among the 8 flagged as problematic. We don’t hide these results. We judge whether a technique worked by its regression-gate score, and treat rejecting it as a result in its own right. At the same time, we show improvements in the same way: adding a filter takes results from 0/20 to 20/20, while switching embedding models raises recall@5 from 0.73 to 1.00. We track accuracy, refusals, leaks, latency, and cost in a single repository from start to finish, then complete the release checklist.

By the end of this course,

  • Measure accuracy and hallucination rates for a standalone LLM, keyword search, and RAG using the same set of questions, then build your own first RAG in 100 lines of code.

  • Select embedding models, chunking strategies (length, overlap, and document structure), and metadata by comparing recall across 60 questions, and handle document updates and model replacements using zero-downtime procedures.

  • Read HNSW indexes, filtered searches, and execution plans in PostgreSQL+pgvector, and fix pitfalls where adding conditions results in zero results.

  • Accept or reject hybrid search, reranking, and query transformation based on regression gate scores, and analyze failures when they prove ineffective.

  • Create and review the gold set, separately measure the accuracy of retrieval, answers, and LLM-as-judge graders, and automatically generate an evaluation report.

  • Block unauthorized documents with row-level security, and use a test set to measure prompt injection defenses, personal information protection, output guardrails, and audit logging.

  • Put Text-to-SQL and tool-calling agents behind read-only accounts, time limits, and human approval, and use a checklist to verify costs, latency, caching, and fallback paths for outages.

Recommended for people like these

  • Backend and data developers who can read Python code and are responsible for connecting LLMs to internal documents and databases.

  • Engineers responsible for bringing AI into their organization who need to report on accuracy, security, and costs with evidence.

  • Those who have built a RAG demo but want to use metrics to determine whether their improvements actually worked.

Curriculum (8 sections · 48 lessons · approximately 639 minutes)

  • Section 1. Run It First — Local Models and Your First RAG — One question, three answers; launch the practice environment all at once; the basics of calling local LLMs; prompts and output formats; measuring hallucinations; your first RAG pipeline in a hundred lines

  • Section 2: Embeddings and Chunking — Embeddings and Similarity, Comparing Embedding Models, Chunking 1: Length and Overlap, Chunking 2: Splitting Along Document Structure, Metadata Design, Document Updates and Reloading

  • Section 3. Vector DB — Store and search with pgvector — pgvector basics, vector indexes HNSW·IVFFlat, bulk loading and storage size, combining filters with vector search, vector search through execution plans, operating embedding model replacements

  • Section 4. Search Quality — Hybrid Search, Reranking, and Query Transformation — Keyword Search with BM25, Is Combining Them Better?, When Reranking Ruined the Rankings, Would Rephrasing the Question Help?, What the Citation Checker Missed, What Does “That” Mean?

  • Section 5. Evaluation — Gold Sets and Regression Gates — Reviewing the gold set, scoring retrieval separately, grading the grader, a gate to run after every change, when fixes don’t improve results, automating evaluation reports

  • Section 6. Security and Permissions — RAG That Doesn’t Leak — An incident caused by RAG without access controls, two incidents that persisted despite added defenses, hidden instructions in documents, masking made them disappear from the answer, the blocking rule also blocked the correct answer, only one person viewed the restricted document

  • Section 7. Text-to-SQL and Tool-Calling Agents — 17 out of 30 questions, Text-to-SQL safeguards, tool-calling basics, the agent loop, risky tools and human approval, agent evaluation

  • Section 8. Operations — Cost, Latency, Caching, Monitoring, and Incidents — Measuring cost and latency, the trap of similar questions, wrapping RAG in a server, anomalies show up in the numbers first, the day the model server stopped, and whether it’s ready to ship.

Practice environment

Everything runs on my PC. I load about 45 internal documents for the fictional company “NuriSol” (which rents water purifiers and air purifiers)—including public, internal, and restricted documents, as well as superseded versions—and business data (20,000 customers, 30,000 contracts, and 50,000 service requests) into a single PostgreSQL+pgvector container. The models are Ollama’s qwen2.5:3b for generation and bge-m3 for embeddings. Python uses only the standard library plus psycopg. No paid API keys are used, and the cost section only calculates costs by multiplying the measured token count by publicly listed rates. The lab ZIP (llmrag-lab.zip) contains chapter-specific scenarios, starter code, and completed code. Ports are bound only to 127.0.0.1. Model outputs may vary slightly from PC to PC, even with the same settings.

Prerequisites

  • Able to read Python (short scripts mainly using the standard library)

  • Basic Docker usage (pulling images and starting/stopping containers) and basic SQL skills

  • Python 3.10 or later, Docker, and about 8GB of memory are required.

  • The models used are Ollama running on my PC (qwen2.5:3b for generation and bge-m3 for embeddings). No paid API key is required.

  • No prior knowledge of LLM or RAG theory is needed. Part 1 starts from scratch with hands-on measurements.

What This Course Does Not Cover

  • Model training and fine-tuning

  • A course on how to use a specific framework (this course uses code that reveals the underlying principles without relying on a framework)

  • Hands-on cloud deployment and large-scale service infrastructure configuration

Notice

The narration in this course uses a synthetic voice (AI dubbing). All data is fictional and for educational purposes, and numbers may vary depending on the execution environment.

Recommended for
these people

Who is this course right for?

  • A backend/data developer who can read Python code and is responsible for integrating LLMs with internal documents and databases.

  • An engineer responsible for introducing AI internally who must report on accuracy, security, and costs with solid evidence.

  • For those who have built a RAG demo but want to measure whether the improvements actually made a difference.

Need to know before starting?

  • Able to read Python (short scripts mainly using the standard library)

  • Basic Docker usage (pulling images, starting and stopping containers) and SQL fundamentals

  • Python 3.10 or later, Docker, and approximately 8 GB of memory are required.

  • The model uses Ollama running on my PC (generation: qwen2.5:3b, embeddings: bge-m3). No paid API key is required.

  • No theoretical knowledge of LLMs or RAG is required. Part 1 starts with hands-on measurements from the very beginning.

Hello
This is dorian05202988

Career Verified

200

Learners

4

Reviews

3.0

Rating

54

Courses

A data craftsman with over 20 years of experience in databases and IT. As a DBA and manager of a DB Platform team, I work with database platforms and specialize in MySQL, PostgreSQL, Oracle, MongoDB, SQL tuning, AWS, Terraform, and Python. Drawing on experience in the gaming, finance, and IT services industries, I explain database and cloud architecture. I have published 『Oracle Practical Tuning: Learning SQL Patterns』 and 『Oracle Pro*C Practical Project Guide』, and have presented on serverless architectures, database selection, and multi-database strategies at AWS Summit 2018 and 2019 and DataYa Nolja 2020. Recently, I have been working on slow-query analysis and tuning recommendations using Bedrock LLM, automated DB specification sizing, and query workflows through a DB metadata MCP server and Slack bot. I explain database automation for developers and AI applications for non-developers through hands-on exercises tailored to the audience and objectives of each course. Rather than applying AI suggestions as-is, I teach a decision-making framework that verifies result equivalence, execution plans, and observability conditions, and defers action when the supporting evidence is insufficient. Company operational data and credentials are not included in the course materials.

More

Curriculum

All

48 lectures ∙ (10hr 39min)

Course Materials:

Lecture resources
Published: 
Last updated: 

Reviews

Not enough reviews.
Please write a valuable review that helps everyone!

dorian05202988's other courses

Check out other courses by the instructor!

Similar courses

Explore other courses in the same field!

Limited time deal

$48,680.00

24%

$50.60