org.llm4s.javaapi.rag

Members list

Type members

Classlikes

final class JRag extends AutoCloseable

Retrieval-augmented generation from Java: ingest documents, then ask questions that a model answers from the chunks of them that match, with those chunks returned as the answer's sources. It is llm4s-rag's pipeline - chunking, embedding, a vector and keyword (hybrid) search and the answer prompt - with no Scala type in sight.

Retrieval-augmented generation from Java: ingest documents, then ask questions that a model answers from the chunks of them that match, with those chunks returned as the answer's sources. It is llm4s-rag's pipeline - chunking, embedding, a vector and keyword (hybrid) search and the answer prompt - with no Scala type in sight.

try (JRag rag = JRag.builder()
       .embeddings(Llm4s.createDefaultEmbeddingClient().get())
       .llm(Llm4s.createDefaultClient().get())
       .build()
       .get()) {
   rag.ingest(Path.of("docs")).get();
   JRagAnswer answer = rag.ask("How do I configure a provider?").get();
   System.out.println(answer.answer());
   answer.sources().forEach(s -> System.out.println("  " + s.documentId() + " (" + s.score() + ")"));
}

Obtain one from JRag.builder. Every call blocks the calling thread and never throws: a failure - of the embedding provider, the model, a file or an argument - comes back inside the LlmResult, whose getError().getKind() says which, as for JLlmClient and JEmbeddingClient. Interrupting the blocked thread returns a failed result of kind CANCELLED, with the interrupt flag still set.

Different documents may be ingested from several threads at once; ingesting the same document id from two threads at once is not supported. close() releases the store - the SQLite connections, or the memory of an in-memory store

  • and not the clients it was built with, which stay the caller's to close.

Attributes

Companion
object
Supertypes
trait AutoCloseable
class Object
trait Matchable
class Any
object JRag

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
JRag.type