RAG and data pipelines
Retrieval-augmented generation (RAG) answers a question from your own documents: the documents are split into chunks, each chunk is embedded as a vector and stored, and a question retrieves the closest chunks for the model to answer from. This page says which guide covers which part.
The stores, hybrid search, reranking, chunking, the loaders and the RAG pipeline are in the llm4s-rag module; the
Elasticsearch and OpenSearch stores and the Redis and Valkey store are separate modules, named in the
Vector Store guide. New to it? RAG in Scala builds the smallest pipeline first.
The guides, by stage
| Stage | Guide | What it covers |
|---|---|---|
| Load | Document Loaders | Text, files, directories, URLs, a web crawl or S3 as a DocumentLoader; composing loaders; ingest, sync and refresh; SSRF protection and robots.txt |
| Embed | Embeddings | Choosing a provider and model, creating an EmbeddingClient, embedding documents and queries, and keeping dimensions in step with the store |
| Chunk, store, search | Vector Store | The VectorStore API and its backends, metadata filtering, hybrid search (keyword plus vector), reranking and document chunking |
| Rewrite the query | Query Transformers | Rewriting the user’s query before it is embedded: LLMQueryRewriter, IdentityTransformer, chaining, error behaviour and your own transformer |
| Restrict | Permission-Based RAG | Collections, principals and document-level permissions, so that a query retrieves only what the user may read |
| Measure | RAG Evaluation | RAGAS metrics (faithfulness, answer relevancy, context precision and recall) and the benchmarking harness that compares chunking, fusion and embedding strategies |
Putting the stages together
- Modular RAG Example - A sample with ingestion, retrieval and generation as separate modules
- RAG for Enterprise - One production pipeline: large document sets, hybrid search with reranking, permissions, evaluation and cost
- Java RAG - Ingest documents and ask questions from Java with
llm4s-java-rag: answers with their sources - Caching - Cache embeddings (exact) and model responses (semantic)
- RAG Benchmark Results - The RAG benchmarking harness and the results it produced
Data pipelines
Calling a model from a batch or streaming job rather than a request handler:
- Spark and Databricks - Enrich a DataFrame from a Spark job: a client per partition,
ReliableClient, errors as data - Apache Flink - Enrich a Flink 2.x stream from Scala 3:
AsyncDataStream, a client per task built inopen(), dead letters as a side output - Kafka - Enrich a Kafka topic with fs2-kafka: bounded concurrency, retries, a dead-letter topic, offsets committed after the produce