absentRecords method

Future<List<String>> absentRecords()

Records whose embedding job dead-lettered, and so are absent from the index (DV-SEMANTIC-004, reported once per record).

Implementation

Future<List<String>> absentRecords() async {
  final List<String> absent = <String>[];
  for (final DVJobEnvelope<DVJobPayload> envelope
      in await queues.deadLetters(queue)) {
    final String? carried =
        await vectors.readMeta('semantic:job:${envelope.id}');
    if (carried == null) continue;
    final List<String> parts = carried.split('\n');
    if (parts.length != 2 || parts[0] != name) continue;
    final String recordId = parts[1];
    if (absent.contains(recordId)) continue;
    absent.add(recordId);
    if (_reported.add('004:$recordId')) {
      DVObservability.log(
        'The embedding job for "$recordId" in "$name" failed permanently; '
        'the record is absent from the index.',
        level: DVLogLevel.warn,
        code: 'DV-SEMANTIC-004',
        context: <String, Object?>{
          'index': name,
          'record': recordId,
          'error': envelope.lastError,
        },
      );
    }
  }
  return absent;
}