open static method

Future<QdrantEdgeClient> open({
  1. required String path,
  2. required int dim,
  3. Distance distance = Distance.cosine,
})

Open (or create) a shard on disk.

path is a directory — qdrant-edge stores its WAL + segment files under it. The directory is created if it doesn't exist.

dim is the vector dimension. Once a shard is created with a given dim, subsequent opens must pass the same value (the C shim's build_edge_config will fail compatibility check otherwise).

Implementation

static Future<QdrantEdgeClient> open({
  required String path,
  required int dim,
  Distance distance = Distance.cosine,
}) async {
  final client = QdrantEdgeClient._();
  final pathPtr = path.toNativeUtf8();
  final distPtr = distance.wireName.toNativeUtf8();
  final errorOut = calloc<Pointer<Utf8>>();
  try {
    final handle = client._b.qe_shard_open(
      pathPtr.cast(),
      dim,
      distPtr.cast(),
      errorOut.cast(),
    );
    if (handle == nullptr) {
      throw QdrantException(_consumeString(client._b, errorOut) ??
          'qe_shard_open returned null');
    }
    client._shard = handle;
    _finalizer.attach(client, handle, detach: client);
    return client;
  } finally {
    malloc.free(pathPtr);
    malloc.free(distPtr);
    calloc.free(errorOut);
  }
}