org.llm4s.rag

package org.llm4s.rag

Members list

Type members

Classlikes

sealed trait EmbeddingProvider

Embedding provider selection for RAG pipeline.

Embedding provider selection for RAG pipeline.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Ollama
object OpenAI
object Voyage

Attributes

Companion
trait
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
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
// Create pipeline
val rag = RAG.builder()
 .withEmbeddings(EmbeddingProvider.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(EmbeddingProvider.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: EmbeddingProvider, 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[String], pgVectorTableName: Option[String], llmClient: Option[LLMClient], systemPrompt: Option[String], tracer: Option[Tracing], documentLoaders: Seq[DocumentLoader], loadingConfig: LoadingConfig)

Configuration for RAG pipeline.

Configuration for RAG pipeline.

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

Attributes

Example
// Minimal configuration
val config = RAGConfig()
 .withEmbeddings(EmbeddingProvider.OpenAI)
// Full customization with SQLite
val config = RAGConfig()
 .withEmbeddings(EmbeddingProvider.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(EmbeddingProvider.OpenAI)
 .withPgVector("jdbc:postgresql://localhost:5432/mydb", "user", "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