DVSemanticIndex<T> constructor
DVSemanticIndex<T> ({
- required String name,
- required DVEmbedder? embedder,
- required DVVectorAdapter vectors,
- required String idOf(
- T record
- required Map<
String, String Function(T record)> fields, - required Future<
T?> load(- String id
- String? tenantOf(
- T record
- Map<
String, String> attributesOf(- T record
- FutureOr<
bool> canSee(- T record
- DVSearchProvider<
T, Object?> ? keyword, - Map<
String, Object?> toJson(- T record
- List<
DVEmbedder> previousEmbedders = const <DVEmbedder>[], - DVChunking chunking = const DVChunking(),
- Set<
String> sensitiveFields = const <String>{}, - DVQueues queues = const DVQueues(),
- String queue = 'semantic',
- int maxAttempts = 3,
- int refillMultiple = 4,
- DVSemanticMetering? metering,
Implementation
DVSemanticIndex({
required this.name,
required DVEmbedder? embedder,
required this.vectors,
required this.idOf,
required this.fields,
required this.load,
this.tenantOf,
this.attributesOf,
this.canSee,
this.keyword,
this.toJson,
this.previousEmbedders = const <DVEmbedder>[],
this.chunking = const DVChunking(),
this.sensitiveFields = const <String>{},
this.queues = const DVQueues(),
this.queue = 'semantic',
this.maxAttempts = 3,
this.refillMultiple = 4,
this.metering,
}) : embedder = _requireEmbedder(name, embedder) {
if (fields.isEmpty) {
throw ArgumentError.value(fields, 'fields', 'name at least one field');
}
final Set<String> sensitiveSemantic =
fields.keys.toSet().intersection(sensitiveFields);
if (sensitiveSemantic.isNotEmpty) {
throw ArgumentError.value(
sensitiveSemantic.join(', '),
'fields',
'a sensitive field cannot be embedded: its text would reach the '
'vector store and every result that matches it',
);
}
if ((tenantOf != null || canSee != null) && !vectors.canFilter) {
throw DVSemanticConfigError(
'DV-SEMANTIC-002',
'the vector adapter for "$name" cannot filter, and the model is '
'${tenantOf != null ? 'tenant' : 'policy'}-scoped. A vector query '
'returns the k nearest, so a filter applied afterwards shows one '
'caller another\'s rows or none of their own. Use an adapter that '
'filters in the query.',
);
}
if (refillMultiple < 1) {
throw ArgumentError.value(refillMultiple, 'refillMultiple', 'must be positive');
}
_registry[name] = this;
queues.register<DVSemanticJob>(_runJob);
}