import Connection from '../../connection/grpc.js'; import { ConsistencyLevel } from '../../data/index.js'; import { DbVersionSupport } from '../../utils/dbVersion.js'; import { FilterValue } from '../filters/index.js'; import { Aggregator } from '../../graphql/index.js'; import { PrimitiveKeys } from '../../index.js'; import { Bm25OperatorOptions, Bm25QueryProperty, NearVectorInputType, TargetVector } from '../query/types.js'; export type AggregateBaseOptions = { filters?: FilterValue; returnMetrics?: M; }; export type PropertyOf = T extends undefined ? string : keyof T & string; export type AggregateGroupByOptions = AggregateBaseOptions & { groupBy: PropertyOf | GroupByAggregate; }; export type GroupByAggregate = { property: PropertyOf; limit?: number; }; export type AggregateOverAllOptions = AggregateBaseOptions; export type AggregateNearOptions = AggregateBaseOptions & { certainty?: number; distance?: number; objectLimit?: number; targetVector?: TargetVector; }; export type AggregateHybridOptions = AggregateBaseOptions & { alpha?: number; maxVectorDistance?: number; objectLimit?: number; queryProperties?: (PrimitiveKeys | Bm25QueryProperty)[]; targetVector?: TargetVector; vector?: number[]; bm25Operator?: Bm25OperatorOptions; }; export type AggregateGroupByHybridOptions = AggregateHybridOptions & { groupBy: PropertyOf | GroupByAggregate; }; export type AggregateGroupByNearOptions = AggregateNearOptions & { groupBy: PropertyOf | GroupByAggregate; }; export type AggregateBoolean = { count?: number; percentageFalse?: number; percentageTrue?: number; totalFalse?: number; totalTrue?: number; }; export type AggregateDate = { count?: number; maximum?: string; median?: string; minimum?: string; mode?: string; }; export type AggregateNumber = { count?: number; maximum?: number; mean?: number; median?: number; minimum?: number; mode?: number; sum?: number; }; export type AggregateReference = { pointingTo?: string; }; export type AggregateText = { count?: number; topOccurrences?: { occurs?: number; value?: string; }[]; }; export type MetricsInput = MetricsBoolean | MetricsInteger | MetricsNumber | MetricsText | MetricsDate; export type PropertiesMetrics = T extends undefined ? MetricsInput | MetricsInput[] : MetricsInput | MetricsInput[]; export type MetricsBase = { kind: K; propertyName: N; }; export type Option = { [key in keyof A]: boolean; }; export type BooleanKeys = 'count' | 'percentageFalse' | 'percentageTrue' | 'totalFalse' | 'totalTrue'; export type DateKeys = 'count' | 'maximum' | 'median' | 'minimum' | 'mode'; export type NumberKeys = 'count' | 'maximum' | 'mean' | 'median' | 'minimum' | 'mode' | 'sum'; export type MetricsBoolean = MetricsBase & Partial<{ [key in BooleanKeys]: boolean; }>; export type MetricsDate = MetricsBase & Partial<{ [key in DateKeys]: boolean; }>; export type MetricsInteger = MetricsBase & Partial<{ [key in NumberKeys]: boolean; }>; export type MetricsNumber = MetricsBase & Partial<{ [key in NumberKeys]: boolean; }>; export type MetricsText = MetricsBase & { count?: boolean; topOccurrences?: { occurs?: boolean; value?: boolean; }; minOccurrences?: number; }; export type AggregateMetrics = { [K in keyof M]: M[K] extends true ? number : never; }; export type MetricsProperty = PropertyOf; export declare const metrics: () => { aggregate:

>(property: P) => MetricsManager; }; export interface Metrics { /** * Define the metrics to be returned based on a property when aggregating over a collection. Use this `aggregate` method to define the name to the property to be aggregated on. Then use the `text`, `integer`, `number`, `boolean`, `date_`, or `reference` methods to define the metrics to be returned. See [the docs](https://weaviate.io/developers/weaviate/search/aggregate) for more details! */ aggregate:

>(property: P) => MetricsManager; } export declare class MetricsManager> { private propertyName; constructor(property: P); private map; /** * Define the metrics to be returned for a BOOL or BOOL_ARRAY property when aggregating over a collection. * * If none of the arguments are provided then all metrics will be returned. * * @param {('count' | 'percentageFalse' | 'percentageTrue' | 'totalFalse' | 'totalTrue')[]} metrics The metrics to return. * @returns {MetricsBoolean

} The metrics for the property. */ boolean(metrics?: ('count' | 'percentageFalse' | 'percentageTrue' | 'totalFalse' | 'totalTrue')[]): MetricsBoolean

; /** * Define the metrics to be returned for a DATE or DATE_ARRAY property when aggregating over a collection. * * If none of the arguments are provided then all metrics will be returned. * * @param {('count' | 'maximum' | 'median' | 'minimum' | 'mode')[]} metrics The metrics to return. * @returns {MetricsDate

} The metrics for the property. */ date(metrics?: ('count' | 'maximum' | 'median' | 'minimum' | 'mode')[]): MetricsDate

; /** * Define the metrics to be returned for an INT or INT_ARRAY property when aggregating over a collection. * * If none of the arguments are provided then all metrics will be returned. * * @param {('count' | 'maximum' | 'mean' | 'median' | 'minimum' | 'mode' | 'sum')[]} metrics The metrics to return. * @returns {MetricsInteger

} The metrics for the property. */ integer(metrics?: ('count' | 'maximum' | 'mean' | 'median' | 'minimum' | 'mode' | 'sum')[]): MetricsInteger

; /** * Define the metrics to be returned for a NUMBER or NUMBER_ARRAY property when aggregating over a collection. * * If none of the arguments are provided then all metrics will be returned. * * @param {('count' | 'maximum' | 'mean' | 'median' | 'minimum' | 'mode' | 'sum')[]} metrics The metrics to return. * @returns {MetricsNumber

} The metrics for the property. */ number(metrics?: ('count' | 'maximum' | 'mean' | 'median' | 'minimum' | 'mode' | 'sum')[]): MetricsNumber

; /** * Define the metrics to be returned for a TEXT or TEXT_ARRAY property when aggregating over a collection. * * If none of the arguments are provided then all metrics will be returned. * * @param {('count' | 'topOccurrencesOccurs' | 'topOccurrencesValue')[]} metrics The metrics to return. * @param {number} [minOccurrences] The how many top occurrences to return. * @returns {MetricsText

} The metrics for the property. */ text(metrics?: ('count' | 'topOccurrencesOccurs' | 'topOccurrencesValue')[], minOccurrences?: number): MetricsText

; } type KindToAggregateType = K extends 'text' ? AggregateText : K extends 'date' ? AggregateDate : K extends 'integer' ? AggregateNumber : K extends 'number' ? AggregateNumber : K extends 'boolean' ? AggregateBoolean : K extends 'reference' ? AggregateReference : never; export type AggregateType = AggregateBoolean | AggregateDate | AggregateNumber | AggregateText; export type AggregateResult | undefined = undefined> = { properties: T extends undefined ? Record : M extends MetricsInput[] ? { [K in M[number] as K['propertyName']]: KindToAggregateType; } : M extends MetricsInput ? { [K in M as K['propertyName']]: KindToAggregateType; } : undefined; totalCount: number; }; export type AggregatedGeoCoordinate = { latitude: number; longitude: number; distance: number; }; export type AggregateGroupByResult | undefined = undefined> = AggregateResult & { groupedBy: { prop: string; value: string | number | boolean | AggregatedGeoCoordinate | string[] | number[] | boolean[]; }; }; declare class AggregateManager implements Aggregate { connection: Connection; groupBy: AggregateGroupBy; name: string; dbVersionSupport: DbVersionSupport; consistencyLevel?: ConsistencyLevel; tenant?: string; grpcChecker: Promise; private constructor(); private grpc; private gql; base(metrics?: PropertiesMetrics, filters?: FilterValue, groupBy?: PropertyOf | GroupByAggregate): Aggregator; metrics(metrics: MetricsInput<(keyof T & string) | string>): string; static use(connection: Connection, name: string, dbVersionSupport: DbVersionSupport, consistencyLevel?: ConsistencyLevel, tenant?: string): AggregateManager; hybrid>(query: string, opts?: AggregateHybridOptions): Promise>; nearImage>(image: string | Buffer, opts?: AggregateNearOptions): Promise>; nearObject>(id: string, opts?: AggregateNearOptions): Promise>; nearText>(query: string | string[], opts?: AggregateNearOptions): Promise>; nearVector>(vector: NearVectorInputType, opts?: AggregateNearOptions): Promise>; overAll>(opts?: AggregateOverAllOptions): Promise>; do: | undefined = undefined>(query: Aggregator) => Promise>; doGroupBy: | undefined = undefined>(query: Aggregator) => Promise[]>; } export interface Aggregate { /** This namespace contains methods perform a group by search while aggregating metrics. */ groupBy: AggregateGroupBy; /** * Aggregate metrics over the objects returned by a hybrid search on this collection. * * This method requires that the objects in the collection have associated vectors. * * @param {string} query The text query to search for. * @param {AggregateHybridOptions} opts The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ hybrid>(query: string, opts?: AggregateHybridOptions): Promise>; /** * Aggregate metrics over the objects returned by a near image vector search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires a vectorizer capable of handling base64-encoded images, e.g. `img2vec-neural`, `multi2vec-clip`, and `multi2vec-bind`. * * @param {string | Buffer} image The image to search on. This can be a base64 string, a file path string, or a buffer. * @param {AggregateNearOptions} [opts] The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearImage>(image: string | Buffer, opts?: AggregateNearOptions): Promise>; /** * Aggregate metrics over the objects returned by a near object search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires that the objects in the collection have associated vectors. * * @param {string} id The ID of the object to search for. * @param {AggregateNearOptions} [opts] The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearObject>(id: string, opts?: AggregateNearOptions): Promise>; /** * Aggregate metrics over the objects returned by a near vector search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires that the objects in the collection have associated vectors. * * @param {number[]} query The text query to search for. * @param {AggregateNearOptions} [opts] The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearText>(query: string | string[], opts?: AggregateNearOptions): Promise>; /** * Aggregate metrics over the objects returned by a near vector search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires that the objects in the collection have associated vectors. * * @param {number[]} vector The vector to search for. * @param {AggregateNearOptions} [opts] The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearVector>(vector: number[], opts?: AggregateNearOptions): Promise>; /** * Aggregate metrics over all the objects in this collection without any vector search. * * @param {AggregateOptions} [opts] The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects in the collection. */ overAll>(opts?: AggregateOverAllOptions): Promise>; } export interface AggregateGroupBy { /** * Aggregate metrics over the objects grouped by a specified property and returned by a hybrid search on this collection. * * This method requires that the objects in the collection have associated vectors. * * @param {string} query The text query to search for. * @param {AggregateGroupByHybridOptions} opts The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ hybrid>(query: string, opts: AggregateGroupByHybridOptions): Promise[]>; /** * Aggregate metrics over the objects grouped by a specified property and returned by a near image vector search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires a vectorizer capable of handling base64-encoded images, e.g. `img2vec-neural`, `multi2vec-clip`, and `multi2vec-bind`. * * @param {string | Buffer} image The image to search on. This can be a base64 string, a file path string, or a buffer. * @param {AggregateGroupByNearOptions} opts The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearImage>(image: string | Buffer, opts: AggregateGroupByNearOptions): Promise[]>; /** * Aggregate metrics over the objects grouped by a specified property and returned by a near object search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires that the objects in the collection have associated vectors. * * @param {string} id The ID of the object to search for. * @param {AggregateGroupByNearOptions} opts The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearObject>(id: string, opts: AggregateGroupByNearOptions): Promise[]>; /** * Aggregate metrics over the objects grouped by a specified property and returned by a near text vector search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires a vectorizer capable of handling text, e.g. `text2vec-contextionary`, `text2vec-openai`, etc. * * @param {string | string[]} query The text to search for. * @param {AggregateGroupByNearOptions} opts The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearText>(query: string | string[], opts: AggregateGroupByNearOptions): Promise[]>; /** * Aggregate metrics over the objects grouped by a specified property and returned by a near vector search on this collection. * * At least one of `certainty`, `distance`, or `object_limit` must be specified here for the vector search. * * This method requires that the objects in the collection have associated vectors. * * @param {number[]} vector The vector to search for. * @param {AggregateGroupByNearOptions} opts The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects returned by the vector search. */ nearVector>(vector: number[], opts: AggregateGroupByNearOptions): Promise[]>; /** * Aggregate metrics over all the objects in this collection grouped by a specified property without any vector search. * * @param {AggregateGroupByOptions} [opts] The options for the request. * @returns {Promise[]>} The aggregated metrics for the objects in the collection. */ overAll>(opts?: AggregateGroupByOptions): Promise[]>; } declare const _default: typeof AggregateManager.use; export default _default;