Consultas automáticas y citas
Lleve RAG más allá con retrievers que convierten el lenguaje natural en filtros de metadatos y con respuestas que citan sus fuentes para que los usuarios puedan confiar en ellas y verificarlas.
Consultas automáticas y citas es una lección gratuita de LLM Apps in Production (RAG + Vector DB + Caching) en CoddyKit. Esta es la lección 4 de 4. Puedes leer la lección completa abajo gratuitamente — luego la practicas en el navegador con un editor de código integrado y un tutor de IA 24/7. Forma parte de la ruta de aprendizaje de LLM Apps in Production (RAG + Vector DB + Caching), y tu progreso se sincroniza en la web y la app de CoddyKit. El curso de LLM Apps in Production (RAG + Vector DB + Caching) incluye 4 lecciones en total.
Partes de esta lección aún no han sido traducidas y se muestran en inglés.
When Questions Carry Filters
Users ask things like give me 2023 reports about pricing. That sentence contains a filter (year 2023) and a semantic query (pricing).
A self-querying retriever automatically separates the two.
How Self-Querying Works
An LLM reads the question and emits a structured query: the semantic search string plus a metadata filter. The retriever then applies both to the vector store.
Describing Your Metadata
You tell the retriever what fields exist so it knows what it can filter on.
from langchain.chains.query_constructor.schema import AttributeInfo
fields = [
AttributeInfo(name='year', description='Publication year', type='integer'),
AttributeInfo(name='topic', description='Document topic', type='string')
]Building the Retriever
Combine the LLM, the store, a content description, and the field info into a self-query retriever.
from langchain.retrievers.self_query.base import SelfQueryRetriever
retriever = SelfQueryRetriever.from_llm(
llm, vectorstore,
'Company reports', fields
)Seeing It in Action
Now a natural-language question is split into a filter and a search automatically — no manual filter code.
docs = retriever.invoke(
'pricing reports from 2023'
)Why Citations Matter
In production, users must be able to verify answers. Unsourced answers are hard to trust and hide hallucinations. Citations link each claim back to its document.
Carrying Source Metadata
Citations rely on each chunk storing where it came from — file name, page, or URL — in its metadata. Set this at load time.
doc.metadata['source'] = 'policy.pdf#p3'Prompting for Citations
Number the context chunks and ask the model to cite the numbers it used. This is simple and reliable.
ctx = '\n'.join(
f'[{i}] {d.page_content}'
for i, d in enumerate(docs)
)
# 'Cite sources like [1] after each claim.'Mapping Numbers to Sources
After generation, map the cited numbers back to real source metadata so the UI can show clickable references.
sources = {i: d.metadata['source']
for i, d in enumerate(docs)}Verifying Citations
Models sometimes cite wrong or nonexistent sources. A safety check confirms each cited chunk actually supports the claim, flagging unsupported statements.
Putting It Together
Self-querying gets the right documents using filters in the question; citations make the resulting answer transparent. Together they raise both precision and trust in advanced RAG.
Quick Check
Test your advanced RAG knowledge.
Recap
You learned two advanced RAG techniques:
- Self-querying turns natural language into metadata filters plus a semantic query
- Describe your fields so the LLM knows what to filter
- Citations link claims to sources for trust
- Carry source metadata, prompt for citations, and verify them
Filtering and citing together make RAG both precise and trustworthy.
Preguntas frecuentes
¿La lección «Consultas automáticas y citas» es gratis?
Sí — el texto completo de «Consultas automáticas y citas» es gratis para leer aquí en la web. Para practicarla de forma interactiva (editor de código integrado y tutor de IA 24/7) y desbloquear el resto del curso de LLM Apps in Production (RAG + Vector DB + Caching), actualiza a CoddyKit PRO. El curso de LLM Apps in Production (RAG + Vector DB + Caching) incluye 4 lecciones en total.
¿Qué aprenderé en «Consultas automáticas y citas»?
Lleve RAG más allá con retrievers que convierten el lenguaje natural en filtros de metadatos y con respuestas que citan sus fuentes para que los usuarios puedan confiar en ellas y verificarlas. Practicas LLM Apps in Production (RAG + Vector DB + Caching) con código real que ejecutas directamente en el navegador, y un tutor de IA 24/7 responde tus preguntas mientras trabajas en la lección.
¿Necesito experiencia previa para empezar LLM Apps in Production (RAG + Vector DB + Caching)?
No se requiere experiencia previa. LLM Apps in Production (RAG + Vector DB + Caching) en CoddyKit está estructurado para principiantes hasta estudiantes avanzados, así que puedes empezar aquí o desde el inicio y avanzar a tu ritmo. Esta es la lección 4 de 4.
¿Cuánto tiempo toma la lección «Consultas automáticas y citas»?
La mayoría de las lecciones de CoddyKit toman alrededor de 5–10 minutos. Cada una es compacta e interactiva, así que avanzas constantemente y retomas exactamente por donde dejaste en la web y la app.
¿Puedo escribir y ejecutar código en esta lección de LLM Apps in Production (RAG + Vector DB + Caching)?
Sí. Cada lección de LLM Apps in Production (RAG + Vector DB + Caching) incluye un editor de código integrado, así que escribes y ejecutas código real directamente en tu navegador y obtienes retroalimentación instantánea de IA — sin configuración local necesaria.
Todas las lecciones de este curso
- Reescritura y reranking de consultas
- Patrones RAG multi etapa y agénticos
- Gestión de estructuras de documentos complejas
- Consultas automáticas y citas