org.llm4s.rag

package org.llm4s.rag

Members list

Type members

Classlikes

final class RAG extends Closeable

High-level RAG (Retrieval-Augmented Generation) pipeline.

High-level RAG (Retrieval-Augmented Generation) pipeline.

Provides a unified interface for:

  • Document ingestion (from files, directories, or raw text)
  • Semantic search with hybrid fusion
  • Answer generation with retrieved context

Attributes

Example
import org.llm4s.chunking.ChunkerFactory
import org.llm4s.config.Llm4sConfig
import org.llm4s.model.ModelRegistryService
import org.llm4s.rag.RAG
import org.llm4s.rag.RAG.RAGConfigOps // `build` is an extension of RAGConfig; without this import it is not found
// `build` also needs a ModelRegistryService and a ProviderRegistry in scope. The registry
// below comes from `Llm4sConfig.modelRegistryService()`; ProviderRegistry.default is a given already.
given ModelRegistryService = Llm4sConfig.modelRegistryService().toOption.get
// Create pipeline
val rag = RAG.builder()
 .withEmbeddings("openai")
 .withChunking(ChunkerFactory.Strategy.Sentence, 800, 150)
 .build
 .toOption.get
// Ingest documents
rag.ingest("./docs")
// Search
val results = rag.query("What is X?")
// With answer generation (requires LLM client)
val ragWithLLM = RAG.builder()
 .withEmbeddings("openai")
 .withLLM(llmClient)
 .build
 .toOption.get
val answer = ragWithLLM.queryWithAnswer("What is X?")
Companion
object
Supertypes
trait Closeable
trait AutoCloseable
class Object
trait Matchable
class Any
object RAG

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
RAG.type
final case class RAGAnswerResult(answer: String, question: String, contexts: Seq[RAGSearchResult], usage: Option[TokenUsage])

Result from RAG answer generation.

Result from RAG answer generation.

Value parameters

answer

The generated answer text

contexts

The chunks used as context for generation

question

The original question

usage

Optional token usage statistics

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class RAGConfig(embeddingProvider: ProviderId, embeddingModel: Option[String], embeddingDimensions: Option[Int], chunkingStrategy: Strategy, chunkingConfig: ChunkingConfig, fusionStrategy: FusionStrategy, topK: Int, rerankingStrategy: RerankingStrategy, rerankTopK: Int, vectorStorePath: Option[String], keywordIndexPath: Option[String], pgVectorConnectionString: Option[String], pgVectorUser: Option[String], pgVectorPassword: Option[Secret], pgVectorTableName: Option[String], pgKeywordTableName: Option[String], llmClient: Option[LLMClient], systemPrompt: Option[String], tracer: Option[Tracing], documentLoaders: Seq[DocumentLoader], loadingConfig: LoadingConfig, searchIndex: Option[SearchIndex], queryTransformers: Seq[QueryTransformer], graphStore: Option[GraphStore], graphRAGConfig: GraphRAGConfig)

Configuration for RAG pipeline.

Configuration for RAG pipeline.

Uses immutable copy pattern for fluent configuration. All settings have sensible defaults for quick start.

Value parameters

embeddingModel

the model to embed with. When None, the model of the resolved provider config is used, then the provider's own default.

embeddingProvider

id of the embedding provider, resolved through the org.llm4s.llmconnect.spi.ProviderRegistry when the pipeline is built - the same id as in EMBEDDING_MODEL=<id>/<model>. Any provider on the classpath can be named, and one that is not fails the build with the registry's "not registered" error.

Attributes

Example
// Minimal configuration
val config = RAGConfig()
 .withEmbeddings("openai")
// Full customization with SQLite
val config = RAGConfig()
 .withEmbeddings("openai", "text-embedding-3-large")
 .withChunking(ChunkerFactory.Strategy.Sentence, 800, 150)
 .withRRF(60)
 .withSQLite("./rag.db")
 .withLLM(llmClient)
// Using PostgreSQL with pgvector
val config = RAGConfig()
 .withEmbeddings("openai")
 .withPgVector("jdbc:postgresql://localhost:5432/mydb", "user", Secret("pass"), "embeddings")
Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object RAGConfig

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
RAGConfig.type
final case class RAGSearchResult(id: String, content: String, score: Double, metadata: Map[String, String], vectorScore: Option[Double], keywordScore: Option[Double])

Result from RAG search operation.

Result from RAG search operation.

Value parameters

content

The text content of the chunk

id

Chunk identifier

keywordScore

Optional keyword match score

metadata

Additional metadata (source, docId, etc.)

score

Combined relevance score

vectorScore

Optional vector similarity score

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class RAGStats(documentCount: Int, chunkCount: Int, vectorCount: Long)

RAG pipeline statistics.

RAG pipeline statistics.

Value parameters

chunkCount

Number of chunks indexed

documentCount

Number of documents indexed

vectorCount

Number of vectors in store

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
sealed trait RerankingStrategy

Reranking strategy for RAG pipeline.

Reranking strategy for RAG pipeline.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Cohere
object LLM
object None

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type