Skip to content

RAG in Python: Give an AI Assistant Sources It Can Actually Retrieve

Understand document ingestion, retrieval and generation. RAG isn't perfect memory, and safe use requires source checks and access controls.

RAG in Python: Give an AI Assistant Sources It Can Actually Retrieve
In this article

You have documents about your product, but the assistant answers as if it has never seen them. Sending the entire knowledge base in every prompt can be costly. Retrieval-Augmented Generation (RAG) offers another option: find relevant passages and supply them when the model answers.

That’s not the same as giving an agent perfect memory. Retrieved information can be wrong, outdated or unavailable to the current user.

In brief: A typical RAG system ingests documents, retrieves relevant passages and generates an answer. Vector databases can help with search, but aren’t mandatory for every dataset. A useful first test checks sources, missing answers and access controls before measuring costs.

Advertisement Precivo

Retrieval is not human memory

Suppose a small store keeps delivery and return policies in separate documents. A retrieval step can select a passage from the appropriate file and ask the model to cite it.

The retrieved document may still be stale, and two policies may contradict each other. A trustworthy workflow needs provenance, updates and a way to say “the supplied documents do not answer this question.”

Conversation history and knowledge retrieval are distinct features. They can complement each other without being equivalent.

The three steps in a minimal system

Ingestion: read permitted documents, record their version and origin, split them into useful passages and index them for search. Chunk boundaries change what gets retrieved.

Retrieval: select relevant passages for a question. Keyword search may be sufficient for a tiny corpus; embeddings and vector search can help with larger or semantically varied documents.

Generation: provide the authorised passages to the model and request citations. Missing or contradictory evidence should remain visible.

Current implementation guidance is available from Chroma, Qdrant and OpenAI embeddings. Pin versions and verify any example with your real environment.

Advertisement Flokin

The most important failure isn’t just a hallucination

A multi-tenant RAG application must prevent user A from retrieving user B’s private documents. Vector search is not an authorisation system on its own. Enforce permission filters in data access and validate them before sending any retrieved text to the model.

You also need reindexing, retention, deletion, backups, privacy controls and error handling. An in-memory demonstration isn’t a production deployment.

Local inference can avoid hosted per-token fees but still incurs hardware, energy and operational costs.

Pricing a RAG product

The original version quoted typical customer fees and a universal monthly cost for thousands of queries without observed usage or a defined token budget. Those amounts were hypotheses, not proven market rates or measured bills.

To evaluate a service, count ingest costs, query tokens, storage, retried calls, hosting and human reviews. Confirm that potential customers value the result before assigning a monthly price.

The workbench: five known answers

Create two fictional documents: one says delivery takes five business days, another says a return can be requested within seven days. Include a question whose answer does not exist in either file.

Write five expected answers by hand. Test retrieval and note whether the correct file is cited, whether contradictions are flagged and whether the system refuses to guess.

Then use two separate fictional accounts and make sure each cannot retrieve the other’s documents. A cross-account leak is a test failure, even if the answer itself is accurate.

The Solo verdict

Our straight take: is it worth your time?

Explore RAG when your assistant regularly needs specific external information. For a small base, a simpler search can be better than maintaining a vector platform.

The practical question is whether retrieving a checkable source improves the result without exposing information to the wrong person.

Sources: Chroma, Qdrant, OpenAI embeddings, Supabase RLS. Review: November 21, 2026.

Up next Tutorials Run a small business? Learn how to promote your products with AI 4 min read

Advertise

Solopreneurs, makers and creators who use AI and automation every day. Editorial and media formats for brands that bring real value to this reader.

Talk to us about formats

Every partnership goes through editorial approval. No misleading promises.

  1. Sponsored articles Useful content, in the Caminho Solo tone and standard.
  2. Banners and display Placements in strategic areas of the site.
  3. Commercial partnerships Series sponsorships, affiliate partnerships, and custom campaigns.
  4. Native content Guides, tutorials or comparisons featuring your product.

Get in touch

Let's talk

Have questions, suggestions, or want to collaborate? Fill out the form below and we'll get back to you soon.

Prefer email?

contato@caminhosolo.com.br

We respect your privacy. Your data will only be used to respond to your message.