Overview
The data flow consists of two main pipelines:Ingestion Pipeline
Document → Nodes → Embeddings → Vector Store
Query Pipeline
Query → Embedding → Retrieval → Synthesis → Response
Ingestion Pipeline
The ingestion pipeline transforms raw documents into searchable vector embeddings.Step 1: Document Loading
Load documents
From @llamaindex/core/schema/node.ts
Step 2: Node Parsing (Chunking)
Documents are split into smaller chunks called Nodes:Node parsing
Context Window Limits
Context Window Limits
LLMs have maximum context windows (e.g., 4K, 8K, 128K tokens). Chunking ensures content fits within these limits.
Semantic Coherence
Semantic Coherence
Smaller chunks often represent more coherent semantic units, improving retrieval accuracy.
Granular Retrieval
Granular Retrieval
Fine-grained chunks allow more precise retrieval of relevant information.
BaseNode from @llamaindex/core/schema
Step 3: Embedding Generation
Each node is converted to a vector embedding:Generate embeddings
From packages/llamaindex/src/indices/vectorStore/index.ts
Embeddings are vector representations of text that capture semantic meaning. Similar texts have similar embeddings.
Step 4: Vector Store Insertion
Nodes with embeddings are stored in a vector database:Store in vector database
- Node ID
- Embedding vector
- Node content (if
storesText: true) - Metadata for filtering
Complete Ingestion Example
Full ingestion pipeline
Advanced: IngestionPipeline
For more control, use theIngestionPipeline:
Custom ingestion pipeline
Query/Retrieval Pipeline
The query pipeline retrieves relevant nodes and synthesizes responses.Step 1: Query Embedding
Query embedding
Step 2: Vector Similarity Search
Retrieve similar nodes
packages/llamaindex/src/indices/vectorStore/index.ts
Step 3: Response Synthesis
Retrieved nodes are sent to the LLM to generate a response:Query engine
- Query is embedded
- Top-K similar nodes are retrieved
- Nodes are formatted into a context
- LLM generates response using context + query
Step 4: Post-Processing (Optional)
Apply reranking or filtering:Reranking
Complete Query Example
Full query pipeline
Chat Engine Flow
Chat engines maintain conversation history:Chat engine
Streaming Responses
Stream responses for better UX:Streaming
Data Flow Optimization
Chunk Size
Smaller chunks = more precise retrieval but more chunks to searchLarger chunks = more context but less precision
Top-K
Higher K = more context but slower and more expensiveLower K = faster but might miss relevant info
Embedding Model
Better embeddings = better retrieval accuracyLarger dimensions = more accurate but slower
Reranking
Post-retrieval reranking improves precisionUse similarity cutoff to filter low-quality matches
Best Practices
1
Consistent Embeddings
Use the same embedding model for both indexing and querying
2
Optimal Chunk Size
Test different chunk sizes (512, 1024, 2048) for your use case
3
Metadata Filtering
Use metadata to filter retrieval results (e.g., by date, source, category)
4
Monitor Performance
Track retrieval quality with evaluation metrics
5
Cache Embeddings
Use IngestionPipeline caching to avoid re-embedding unchanged documents
Next Steps
Vector Indices
Deep dive into VectorStoreIndex configuration and usage
Query Engines
Learn about different query engine types and customization
Ingestion Pipeline
Advanced ingestion pipeline patterns and transformations