Performs similarity search on text string.
The API expects a TFLite model with optional, but strongly recommended, TFLite Model Metadata..
The API expects a TFLite model with metadata populated. The metadata should contain the following information:
TODO(b/180502532): add pointer to example model.
TODO(b/222671076): add factory create methods without options, such as `createFromFile`, once the single file format (index file packed in the model) is supported.
class | TextSearcher.TextSearcherOptions | Options for setting up an TextSearcher. |
static TextSearcher |
createFromBufferAndOptions(ByteBuffer modelBuffer, TextSearcher.TextSearcherOptions options)
Creates an
TextSearcher instance with a model buffer and TextSearcher.TextSearcherOptions . |
static TextSearcher |
createFromBufferAndOptionsImpl(ByteBuffer modelBuffer, TextSearcher.TextSearcherOptions options, int indexFd)
|
static TextSearcher |
createFromFileAndOptions(File modelFile, TextSearcher.TextSearcherOptions options)
Creates an
TextSearcher instance. |
static TextSearcher |
createFromFileAndOptions(Context context, String modelPath, TextSearcher.TextSearcherOptions options)
Creates an
TextSearcher instance from TextSearcher.TextSearcherOptions . |
List<NearestNeighbor> |
Creates an TextSearcher
instance with a model buffer and TextSearcher.TextSearcherOptions
.
modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the search
model |
---|---|
options |
IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a
MappedByteBuffer |
---|---|
IOException | if an I/O error occurs when loading the index file |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
modelBuffer | |
---|---|
options | |
indexFd |
Creates an TextSearcher
instance.
modelFile | the search model File instance |
---|---|
options |
IOException | if an I/O error occurs when loading the tflite model or the index file |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
Creates an TextSearcher
instance from TextSearcher.TextSearcherOptions
.
context | |
---|---|
modelPath | path of the search model with metadata in the assets |
options |
IOException | if an I/O error occurs when loading the tflite model or the index file |
---|---|
IllegalArgumentException | if an argument is invalid |
IllegalStateException | if there is an internal error |
RuntimeException | if there is an otherwise unspecified error |
Performs embedding extraction on the provided string input, followed by nearest-neighbor search in the index.
text | input text query to the model |
---|