import { WeaviateField } from '../index.js'; import { PrimitiveVectorType } from '../query/types.js'; import { CrossReferenceDefault } from '../references/index.js'; import { ExtractCrossReferenceType, NonRefKeys, QueryNestedDefault, QueryProperty, QueryReference, RefKeys } from './internal.js'; export type SearchProfile = { details: Record; }; export type ShardProfile = { name: string; node: string; searches: Record; }; export type QueryProfile = { shards: ShardProfile[]; }; export type Metadata = { creationTime: Date; updateTime: Date; distance: number; certainty: number; score: number; explainScore: string; rerankScore: number; isConsistent: boolean; }; export type MetadataKeys = (keyof Metadata | 'all' | 'queryProfile')[]; export type QueryMetadata = 'all' | MetadataKeys | undefined; export type ReturnMetadata = Partial; export type WeaviateGenericObject = { /** The generic returned properties of the object derived from the type `T`. */ properties: ReturnProperties; /** The returned metadata of the object. */ metadata: ReturnMetadata | undefined; /** The returned references of the object derived from the type `T`. */ references: ReturnReferences | undefined; /** The UUID of the object. */ uuid: string; /** The returned vectors of the object. */ vectors: V; }; export type WeaviateNonGenericObject = { /** The returned properties of the object. */ properties: Record; /** The returned metadata of the object. */ metadata: ReturnMetadata | undefined; /** The returned references of the object. */ references: Record | undefined; /** The UUID of the object. */ uuid: string; /** The returned vectors of the object. */ vectors: Vectors; }; export type ReturnProperties = Pick>; export type ReturnReferences = Pick>; export interface Vectors { [k: string]: PrimitiveVectorType; } export type ReturnVectors = V extends undefined ? undefined : I extends true ? V : I extends Array ? Pick : never; /** An object belonging to a collection as returned by the methods in the `collection.query` namespace. * * Depending on the generic type `T`, the object will have subfields that map from `T`'s specific type definition. * If not, then the object will be non-generic and have a `properties` field that maps from a generic string to a `WeaviateField`. */ export type WeaviateObject = T extends undefined ? V extends undefined ? WeaviateNonGenericObject : WeaviateGenericObject : V extends undefined ? WeaviateGenericObject : WeaviateGenericObject; /** The return of a query method in the `collection.query` namespace. */ export type WeaviateReturn = { /** The objects that were found by the query. */ objects: WeaviateObject[]; /** The metadata about the query execution. This contains different datastructures depending on the search type, e.g. vector vs keyword. */ queryProfile?: QueryProfile; }; export type GroupByObject = WeaviateObject & { belongsToGroup: string; }; export type GroupByResult = { name: string; minDistance: number; maxDistance: number; numberOfObjects: number; objects: WeaviateObject[]; }; /** The return of a query method in the `collection.query` namespace where the `groupBy` argument was specified. */ export type GroupByReturn = { /** The objects that were found by the query. */ objects: GroupByObject[]; /** The groups that were created by the query. */ groups: Record>; /** The metadata about the query execution. This contains different datastructures depending on the search type, e.g. vector vs keyword. */ queryProfile?: QueryProfile; }; export type GroupByOptions = T extends undefined ? { property: string; numberOfGroups: number; objectsPerGroup: number; } : { property: keyof T; numberOfGroups: number; objectsPerGroup: number; }; export type RerankOptions = T extends undefined ? { property: string; query: string; } : { property: keyof T; query?: string; }; export interface BaseRefProperty { /** The property to link on when defining the references traversal. */ linkOn: RefKeys; /** Whether to return the vector(s) of the referenced objects in the query. */ includeVector?: boolean | string[]; /** The metadata to return for the referenced objects. */ returnMetadata?: QueryMetadata; /** The properties to return for the referenced objects. */ returnProperties?: QueryProperty>[]; /** The references to return for the referenced objects. */ returnReferences?: QueryReference>[]; /** The collection to target when traversing the references. Required for multi-target references. */ targetCollection?: string; } export type RefProperty = BaseRefProperty; export type RefPropertyDefault = { /** The property to link on when defining the references traversal. */ linkOn: string; /** Whether to return the vector(s) of the referenced objects in the query. */ includeVector?: boolean | string[]; /** The metadata to return for the referenced objects. */ returnMetadata?: QueryMetadata; /** The properties to return for the referenced objects. */ returnProperties?: (string | QueryNestedDefault)[]; /** The references to return for the referenced objects. */ returnReferences?: RefPropertyDefault[]; /** The collection to target when traversing the references. Required for multi-target references. */ targetCollection?: string; }; export type SortBy = { property: string; ascending?: boolean; };