匠人学院 JR Academy
Skip to article
Learning guide
LlamaIndex Guide

Use LlamaIndex to connect data sources, indexing pipelines, and retrieval workflows for RAG apps.

2 chapters·4 guides·Access varies by chapter
Query Engines
On this page

LlamaIndex Querying and Retrieval

Control what is retrieved, how much is retrieved, whether results are reranked and how evidence reaches the answer.

#Query engine

python
query_engine = index.as_query_engine() response = query_engine.query("Summarize this document.") print(response.response) print(response.source_nodes)

The response text and its source nodes should be inspected together.

#Retrieval without answer generation

python
retriever = index.as_retriever(similarity_top_k=3) nodes = retriever.retrieve("What is a vector database?")

#Additional patterns

A chat engine can retain conversational context:

python
chat_engine = index.as_chat_engine() chat_engine.chat("My name is Alex.") response = chat_engine.chat("What name did I give you?")

A router can select among indexes. A sub-question workflow can divide a comparison into smaller retrieval tasks and combine the results. Neither is necessary for every query.

#Retrieval improvements

Metadata filters restrict the relevant dates/categories. Reranking can narrow a larger initial set—for example twenty candidates to three reviewed passages. Hybrid search combines semantic and keyword signals. Measure basic recall before adding each stage.

#Structured responses

python
from pydantic import BaseModel class Info(BaseModel): name: str amount: float query_engine = index.as_query_engine(output_cls=Info)

This illustrates a typed output target; validate the selected integration's support and the actual returned values.

If answers are only partly reliable, inspect top_k, metadata scope and candidate ordering before changing the generation prompt or model.

Published by
JR Academy
Learning resources

Individual authors and reviewers are credited where recorded.

System Design

Core system design concepts and practical case studies

Learn the trade-offs and patterns that matter in technical interviews.

Open System Design →

Related Roadmaps

Done reading? Next steps