upsertAll method

  1. @override
Future<void> upsertAll(
  1. List<VectorUpsert> upserts
)
override

Implementation

@override
Future<void> upsertAll(List<VectorUpsert> upserts) async {
  try {
    if (upserts.isEmpty) {
      return;
    }

    await ensureCollection();
    List<DenseVector> openAiVectors = await onEmbed(
      upserts.map((i) => i.content).toList(),
    );
    await points.upsert(
      UpsertPoints(
        collectionName: namespace,
        wait: false,
        points: [
          for (int i = 0; i < upserts.length; i++)
            PointStruct(
              id: _pointIdFor(upserts[i].id),
              vectors: Vectors(vector: Vector(dense: openAiVectors[i])),
              payload:
                  {
                    "id": Value(stringValue: upserts[i].id),
                    "text": Value(stringValue: upserts[i].content),
                    if (upserts[i].metadata["record"] is String)
                      "record": Value(
                        stringValue: upserts[i].metadata["record"] as String,
                      ),
                    if (upserts[i].metadata["entry"] is String)
                      "entry": Value(
                        stringValue: upserts[i].metadata["entry"] as String,
                      ),
                    if (upserts[i].metadata.isNotEmpty)
                      "metadata": _toValue(upserts[i].metadata),
                  }.entries,
            ),
        ],
      ),
    );
  } catch (e, es) {
    error("Failed to upsert ${upserts.length} vectors");
    error(e);
    error(es);
  }
}