mostRelevantDocuments

suspend fun <Document> RankedDocumentStorage<Document>.mostRelevantDocuments(query: String, count: Int = Int.MAX_VALUE, similarityThreshold: Double = 0.0): Iterable<Document>(source)

Retrieves the most relevant documents matching the provided query, ranked by their similarity scores in descending order. Only documents with a similarity score greater than or equal to the specified similarity threshold are included, and the result set is limited to the specified count.

Example:

  • mostRelevantDocuments("tigers in the wild nature", 10) - returns top-10 most relevant documents about tigers in the wild nature

  • mostRelevantDocuments("tigers in the wild nature", similarityThreshold = 0.7) - returns all documents about tigers in the wild nature that have at least 70% similarity (relevance) score

  • mostRelevantDocuments("tigers in the wild nature", similarityThreshold = 0.7, count = 10) - returns no more than 10 most relevant documents about tigers in the wild nature that have at least 70% similarity (relevance) score

Return

An iterable collection of the most relevant documents that satisfy the specified filters and rankings.

Parameters

query

The search query used to find relevant documents.

count

The maximum number of documents to return. Defaults to Int.MAX_VALUE if not specified.

similarityThreshold

The minimum similarity score a document must have to be considered relevant. Defaults to 0.0 if not specified.