search method

Future<List<SearchHit>> search({
  1. required List<double> queryVector,
  2. required int topK,
  3. String? filterJson,
})

Top-K nearest-neighbour search. Pass filterJson (encoded via FilterCodec.encode) to constrain results by payload; pass null to run unfiltered.

Implementation

Future<List<SearchHit>> search({
  required List<double> queryVector,
  required int topK,
  String? filterJson,
}) async {
  _checkOpen();
  final vecPtr = _allocFloatVec(queryVector);
  final filterPtr = filterJson == null ? nullptr : filterJson.toNativeUtf8();
  final responseOut = calloc<Pointer<Utf8>>();
  final errorOut = calloc<Pointer<Utf8>>();
  try {
    final int rc;
    if (filterPtr == nullptr) {
      rc = _b.qe_shard_search(
        _shard,
        vecPtr,
        queryVector.length,
        topK,
        responseOut.cast(),
        errorOut.cast(),
      );
    } else {
      rc = _b.qe_shard_search_with_filter(
        _shard,
        vecPtr,
        queryVector.length,
        topK,
        filterPtr.cast(),
        responseOut.cast(),
        errorOut.cast(),
      );
    }
    if (rc != 0) {
      throw QdrantException(
          _consumeString(_b, errorOut) ?? 'qe_shard_search rc=$rc');
    }
    final responseJson = _consumeString(_b, responseOut);
    if (responseJson == null) return const [];
    return _decodeSearchResponse(responseJson);
  } finally {
    malloc.free(vecPtr);
    if (filterPtr != nullptr) malloc.free(filterPtr);
    calloc.free(responseOut);
    calloc.free(errorOut);
  }
}