import { MastraVector } from '@mastra/core/vector'; import type { QueryResult, IndexStats, CreateIndexParams, UpsertVectorParams, QueryVectorParams, DescribeIndexParams, DeleteIndexParams, DeleteVectorParams, UpdateVectorParams, DeleteVectorsParams } from '@mastra/core/vector'; import { QdrantClient } from '@qdrant/js-client-rest'; import type { QdrantClientParams } from '@qdrant/js-client-rest'; import type { QdrantVectorFilter } from './filter.js'; /** * Configuration for a named vector space in Qdrant. * @see https://qdrant.tech/documentation/concepts/vectors/#named-vectors */ export interface NamedVectorConfig { /** The dimension (size) of vectors in this space. */ size: number; /** The distance metric for similarity search. */ distance: 'cosine' | 'euclidean' | 'dotproduct'; } /** * Query parameters for Qdrant vector store. * Extends the base QueryVectorParams with Qdrant-specific options. */ export interface QdrantQueryVectorParams extends QueryVectorParams { /** * Name of the vector field to query against when using named vectors. * Use this when your collection has multiple named vector fields. * @see https://qdrant.tech/documentation/concepts/vectors/#named-vectors */ using?: string; } /** * Parameters for creating a Qdrant index/collection. * Extends the base CreateIndexParams with support for named vectors. */ export interface QdrantCreateIndexParams extends CreateIndexParams { /** * Configuration for named vector spaces. * When provided, creates a collection with multiple named vector fields. * Each key is the vector name, and the value defines its configuration. * @see https://qdrant.tech/documentation/concepts/vectors/#named-vectors * * @example * ```ts * namedVectors: { * text: { size: 768, distance: 'cosine' }, * image: { size: 512, distance: 'euclidean' }, * } * ``` */ namedVectors?: Record; } /** * Parameters for upserting vectors into Qdrant. * Extends the base UpsertVectorParams with support for named vectors. */ export interface QdrantUpsertVectorParams extends UpsertVectorParams { /** * Name of the vector space to upsert into when using named vectors. * Required when the collection was created with namedVectors. * @see https://qdrant.tech/documentation/concepts/vectors/#named-vectors */ vectorName?: string; } /** * Supported payload schema types for Qdrant payload indexes. * These correspond to Qdrant's native payload indexing types. * @see https://qdrant.tech/documentation/concepts/indexing/#payload-index */ export type PayloadSchemaType = 'keyword' | 'integer' | 'float' | 'geo' | 'text' | 'bool' | 'datetime' | 'uuid'; /** * Parameters for creating a payload index on a Qdrant collection. */ export interface CreatePayloadIndexParams { /** The name of the collection (index) to create the payload index on. */ indexName: string; /** The name of the payload field to index. */ fieldName: string; /** The schema type for the payload field. */ fieldSchema: PayloadSchemaType; /** Whether to wait for the operation to complete. Defaults to true. */ wait?: boolean; } /** * Parameters for deleting a payload index from a Qdrant collection. */ export interface DeletePayloadIndexParams { /** The name of the collection (index) to delete the payload index from. */ indexName: string; /** The name of the payload field index to delete. */ fieldName: string; /** Whether to wait for the operation to complete. Defaults to true. */ wait?: boolean; } export declare class QdrantVector extends MastraVector { protected client: QdrantClient; /** * Creates a new QdrantVector client. * @param id - The unique identifier for this vector store instance. * @param url - The URL of the Qdrant server. * @param apiKey - The API key for Qdrant. * @param https - Whether to use HTTPS. */ constructor({ id, ...qdrantParams }: QdrantClientParams & { id: string; }); /** * Validates that a named vector exists in the collection. * @param indexName - The name of the collection to check. * @param vectorName - The name of the vector space to validate. * @throws Error if the vector name doesn't exist in the collection. */ private validateVectorName; /** * Upserts vectors into the index. * @param indexName - The name of the index to upsert into. * @param vectors - Array of embedding vectors. * @param metadata - Optional metadata for each vector. * @param ids - Optional vector IDs (auto-generated if not provided). * @param vectorName - Optional name of the vector space when using named vectors. */ upsert({ indexName, vectors, metadata, ids, vectorName }: QdrantUpsertVectorParams): Promise; /** * Creates a new index (collection) in Qdrant. * Supports both single vector and named vector configurations. * * @param indexName - The name of the collection to create. * @param dimension - Vector dimension (required for single vector mode). * @param metric - Distance metric (default: 'cosine'). * @param namedVectors - Optional named vector configurations for multi-vector collections. * * @example * ```ts * // Single vector collection * await qdrant.createIndex({ indexName: 'docs', dimension: 768, metric: 'cosine' }); * * // Named vectors collection * await qdrant.createIndex({ * indexName: 'multi-modal', * dimension: 768, // Used as fallback, can be omitted with namedVectors * namedVectors: { * text: { size: 768, distance: 'cosine' }, * image: { size: 512, distance: 'euclidean' }, * }, * }); * ``` */ createIndex({ indexName, dimension, metric, namedVectors }: QdrantCreateIndexParams): Promise; transformFilter(filter?: QdrantVectorFilter): QdrantVectorFilter; /** * Queries the index for similar vectors. * * @param indexName - The name of the index to query. * @param queryVector - The query vector to find similar vectors for. * @param topK - Number of results to return (default: 10). * @param filter - Optional metadata filter. * @param includeVector - Whether to include vectors in results (default: false). * @param using - Name of the vector space to query when using named vectors. */ query({ indexName, queryVector, topK, filter, includeVector, using, }: QdrantQueryVectorParams): Promise; listIndexes(): Promise; /** * Retrieves statistics about a vector index. * * @param {string} indexName - The name of the index to describe * @returns A promise that resolves to the index statistics including dimension, count and metric */ describeIndex({ indexName }: DescribeIndexParams): Promise; deleteIndex({ indexName }: DeleteIndexParams): Promise; /** * Updates a vector by its ID or multiple vectors matching a filter. * @param indexName - The name of the index containing the vector(s). * @param id - The ID of the vector to update (mutually exclusive with filter). * @param filter - Filter to match multiple vectors to update (mutually exclusive with id). * @param update - An object containing the vector and/or metadata to update. * @param update.vector - An optional array of numbers representing the new vector. * @param update.metadata - An optional record containing the new metadata. * @returns A promise that resolves when the update is complete. * @throws Will throw an error if no updates are provided or if the update operation fails. */ updateVector({ indexName, id, filter, update }: UpdateVectorParams): Promise; /** * Deletes a vector by its ID. * @param indexName - The name of the index containing the vector. * @param id - The ID of the vector to delete. * @returns A promise that resolves when the deletion is complete. * @throws Will throw an error if the deletion operation fails. */ deleteVector({ indexName, id }: DeleteVectorParams): Promise; /** * Parses and converts a string ID to the appropriate type (string or number) for Qdrant point operations. * * Qdrant supports both numeric and string IDs. This helper method ensures IDs are in the correct format * before sending them to the Qdrant client API. * * @param id - The ID string to parse * @returns The parsed ID as either a number (if string contains only digits) or the original string * * @example * // Numeric ID strings are converted to numbers * parsePointId("123") => 123 * parsePointId("42") => 42 * parsePointId("0") => 0 * * // String IDs containing any non-digit characters remain as strings * parsePointId("doc-123") => "doc-123" * parsePointId("user_42") => "user_42" * parsePointId("abc123") => "abc123" * parsePointId("123abc") => "123abc" * parsePointId("") => "" * parsePointId("uuid-5678-xyz") => "uuid-5678-xyz" * * @remarks * - This conversion is important because Qdrant treats numeric and string IDs differently * - Only positive integers are converted to numbers (negative numbers with minus signs remain strings) * - The method uses base-10 parsing, so leading zeros will be dropped in numeric conversions * - reference: https://qdrant.tech/documentation/concepts/points/?q=qdrant+point+id#point-ids */ private parsePointId; /** * Deletes multiple vectors by IDs or filter. * @param indexName - The name of the index containing the vectors. * @param ids - Array of vector IDs to delete (mutually exclusive with filter). * @param filter - Filter to match vectors to delete (mutually exclusive with ids). * @returns A promise that resolves when the deletion is complete. * @throws Will throw an error if both ids and filter are provided, or if neither is provided. */ deleteVectors({ indexName, filter, ids }: DeleteVectorsParams): Promise; /** * Creates a payload index on a Qdrant collection to enable efficient filtering on metadata fields. * * This is required for Qdrant Cloud and any Qdrant instance with `strict_mode_config = true`, * where metadata (payload) fields must be explicitly indexed before they can be used for filtering. * * @param params - The parameters for creating the payload index. * @param params.indexName - The name of the collection (index) to create the payload index on. * @param params.fieldName - The name of the payload field to index. * @param params.fieldSchema - The schema type for the field (e.g., 'keyword', 'integer', 'text'). * @param params.wait - Whether to wait for the operation to complete. Defaults to true. * @returns A promise that resolves when the index is created (idempotent if index already exists). * @throws Will throw a MastraError if arguments are invalid or if the operation fails. * * @example * ```ts * // Create a keyword index for filtering by source * await qdrant.createPayloadIndex({ * indexName: 'my-collection', * fieldName: 'source', * fieldSchema: 'keyword', * }); * * // Create an integer index for numeric filtering * await qdrant.createPayloadIndex({ * indexName: 'my-collection', * fieldName: 'price', * fieldSchema: 'integer', * }); * ``` * * @see https://qdrant.tech/documentation/concepts/indexing/#payload-index */ createPayloadIndex({ indexName, fieldName, fieldSchema, wait, }: CreatePayloadIndexParams): Promise; /** * Deletes a payload index from a Qdrant collection. * * @param params - The parameters for deleting the payload index. * @param params.indexName - The name of the collection (index) to delete the payload index from. * @param params.fieldName - The name of the payload field index to delete. * @param params.wait - Whether to wait for the operation to complete. Defaults to true. * @returns A promise that resolves when the index is deleted (idempotent if index doesn't exist). * @throws Will throw a MastraError if the operation fails. * * @example * ```ts * await qdrant.deletePayloadIndex({ * indexName: 'my-collection', * fieldName: 'source', * }); * ``` */ deletePayloadIndex({ indexName, fieldName, wait }: DeletePayloadIndexParams): Promise; } //# sourceMappingURL=index.d.ts.map