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.
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.
Answers question from the chunks that match it best, at most the builder's topK: the question is embedded, the chunks found, and the model asked to answer from them alone. The answer lists those chunks as its sources; with nothing indexed it has none, and the model is still asked, so its answer says it cannot tell.
Answers question from the chunks that match it best, at most the builder's topK: the question is embedded, the chunks found, and the model asked to answer from them alone. The answer lists those chunks as its sources; with nothing indexed it has none, and the model is still asked, so its answer says it cannot tell.
A pipeline built without a chat client (llm) returns a failed result of kind CONFIGURATION; a null or blank question one of kind VALIDATION. A failure of the embedding provider or the model has the kind of that failure.
Ingests a file, or every file directly in a directory whose name ends in .txt, .md, .pdf, .docx, .json, .xml or .html, returning how many chunks were indexed. A file's id is its name: ingesting a file of the same name again replaces what was indexed under it. The same as ingest(path, Map.of()).
Ingests a file, or every file directly in a directory whose name ends in .txt, .md, .pdf, .docx, .json, .xml or .html, returning how many chunks were indexed. A file's id is its name: ingesting a file of the same name again replaces what was indexed under it. The same as ingest(path, Map.of()).
Ingests a file or a directory as ingest(path) does, attaching metadata to every chunk; each chunk also gets the file's name as source and its absolute path as path. A null argument, a null key or value, or a path that does not exist is a failed result of kind VALIDATION.
Ingests a file or a directory as ingest(path) does, attaching metadata to every chunk; each chunk also gets the file's name as source and its absolute path as path. A null argument, a null key or value, or a path that does not exist is a failed result of kind VALIDATION.
Ingests text as the document documentId, returning how many chunks were indexed. Ingesting an id again replaces what was indexed under it. The same as ingestText(text, documentId, Map.of()).
Ingests text as the document documentId, returning how many chunks were indexed. Ingesting an id again replaces what was indexed under it. The same as ingestText(text, documentId, Map.of()).
Ingests text as the document documentId, attaching metadata to every chunk. A null argument, a blank id, or a null key or value is a failed result of kind VALIDATION.
Ingests text as the document documentId, attaching metadata to every chunk. A null argument, a blank id, or a null key or value is a failed result of kind VALIDATION.
The chunks that match query best, at most the builder's topK, best first, without asking a model: what ask would answer from. Works with or without a chat client. A null or blank query is a failed result of kind VALIDATION. An unmodifiable list.
The chunks that match query best, at most the builder's topK, best first, without asking a model: what ask would answer from. Works with or without a chat client. A null or blank query is a failed result of kind VALIDATION. An unmodifiable list.