RankedDocumentStorage

Represents a specialization of the DocumentStorage interface that handles ranking documents based on their relevance to a given query. The ranking process returns documents along with a similarity score, enabling the filtering and sorting of documents by relevance.

Parameters

Document

The type of the documents being processed and stored.

Functions

Link copied to clipboard
abstract fun allDocuments(): Flow<Document>

Iterates over the documents

Link copied to clipboard

Iterates through documents and their corresponding payloads

Link copied to clipboard
abstract suspend fun delete(documentId: String): Boolean

Deletes the document with the specified ID from the storage.

Link copied to clipboard
open suspend override fun getPayload(documentId: String)

Retrieves the payload associated with the document identified by the given document ID.

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

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.

Link copied to clipboard

Ranks documents in the storage based on their relevance to the given query. Each document is assigned a similarity score that represents how closely it matches the query.

Link copied to clipboard
abstract suspend fun read(documentId: String): Document?

Reads a document associated with the given document ID and returns it.

Link copied to clipboard
open suspend override fun readWithPayload(documentId: String): DocumentWithPayload<Document, Unit>?

Reads a document along with its associated payload based on the given document ID.

Link copied to clipboard
open suspend fun store(document: Document): String

Stores a document in the storage system without any additional payload.

abstract suspend fun store(document: Document, data: Unit): String

Stores a document and its associated payload in the storage.