diff --git a/src/collections/collection/index.ts b/src/collections/collection/index.ts index c4164352..27c32624 100644 --- a/src/collections/collection/index.ts +++ b/src/collections/collection/index.ts @@ -24,7 +24,7 @@ export interface Collection { /** This namespace includes all the backup methods available to you when backing up a collection in Weaviate. */ backup: BackupCollection; /** This namespace includes all the CRUD methods available to you when modifying the configuration of the collection in Weaviate. */ - config: Config; + config: Config; /** This namespace includes all the CUD methods available to you when modifying the data of the collection in Weaviate. */ data: Data; /** This namespace includes the methods by which you can create the `FilterValue` values for use when filtering queries over your collection. */ @@ -139,7 +139,7 @@ const collection = ( return { aggregate: aggregateCollection, backup: backupCollection(connection, capitalizedName), - config: config(connection, capitalizedName, dbVersionSupport, tenant), + config: config(connection, capitalizedName, dbVersionSupport, tenant), data: data(connection, capitalizedName, dbVersionSupport, consistencyLevel, tenant), filter: filter(), generate: generate(connection, capitalizedName, dbVersionSupport, consistencyLevel, tenant), diff --git a/src/collections/config/index.ts b/src/collections/config/index.ts index 87c8a44e..eaddc38e 100644 --- a/src/collections/config/index.ts +++ b/src/collections/config/index.ts @@ -29,12 +29,12 @@ import { } from './types/index.js'; import { classToCollection, makeVectorsConfig, resolveProperty, resolveReference } from './utils.js'; -const config = ( +const config = ( connection: Connection, name: string, dbVersionSupport: DbVersionSupport, tenant?: string -): Config => { +): Config => { const getRaw = new ClassGetter(connection).withClassName(name).do; return { addProperty: (property: PropertyConfigCreate) => @@ -96,12 +96,14 @@ const config = ( }, dropInvertedIndex: (propertyName, indexName) => connection.delete(`/schema/${name}/properties/${propertyName}/index/${indexName}`, null), + dropVectorIndex: (vectorName) => + connection.delete(`/schema/${name}/vectors/${vectorName ? String(vectorName) : 'default'}/index`, null), }; }; export default config; -export interface Config { +export interface Config { /** * Add a property to the collection in Weaviate. * @@ -173,6 +175,17 @@ export interface Config { * @returns {Promise} A promise that resolves when the index has been dropped. */ dropInvertedIndex: (propertyName: string, indexName: InvertedIndexName) => Promise; + /** + * Drop the vector index associated with a named vector of this collection. + * + * This is a destructive operation. The index will need to be regenerated if you wish to use it again. + * + * @param {keyof V & string} [vectorName] The name of the vector to drop the index from. If not provided, the default vector index will be dropped. + * @returns {Promise} A promise that resolves when the index has been dropped. + */ + dropVectorIndex: ( + vectorName?: VN + ) => Promise; } export class VectorIndex { diff --git a/src/collections/config/types/vectorIndex.ts b/src/collections/config/types/vectorIndex.ts index 99dbfdb9..171d3397 100644 --- a/src/collections/config/types/vectorIndex.ts +++ b/src/collections/config/types/vectorIndex.ts @@ -111,7 +111,7 @@ export type VectorDistance = 'cosine' | 'dot' | 'l2-squared' | 'hamming'; export type PQEncoderType = 'kmeans' | 'tile'; export type PQEncoderDistribution = 'log-normal' | 'normal'; -export type VectorIndexType = 'hnsw' | 'hfresh' | 'flat' | 'dynamic' | string; +export type VectorIndexType = 'hnsw' | 'hfresh' | 'flat' | 'dynamic' | 'none' | string; export type VectorIndexFilterStrategy = 'sweeping' | 'acorn'; diff --git a/test/collections/config/integration.test.ts b/test/collections/config/integration.test.ts index 69964789..907ae23b 100644 --- a/test/collections/config/integration.test.ts +++ b/test/collections/config/integration.test.ts @@ -1085,6 +1085,76 @@ describe('Testing of the collection.config namespace', () => { }); }); + requireAtLeast(1, 37, 0).describe('dropVectorIndex', () => { + it('should drop default vector index from a collection', async () => { + const collectionName = 'TestDropDefaultVectorIndex'; + const collection = await client.collections.create({ + name: collectionName, + vectorizers: weaviate.configure.vectors.selfProvided({ + vectorIndexConfig: weaviate.configure.vectorIndex.hnsw(), + }), + }); + + let config = await collection.config.get(); + expect(config.vectorizers.default.indexType).toEqual('hnsw'); + + await collection.config.dropVectorIndex(); + + config = await collection.config.get(); + expect(config.vectorizers.default.indexType).toEqual('none'); + }); + + it('should throw an error when trying to drop a non-existent named vector index', async () => { + const collectionName = 'TestDropNonExistentNamedVectorIndex'; + const collection = await client.collections.create({ + name: collectionName, + vectorizers: weaviate.configure.vectors.selfProvided({ + name: 'existing', + vectorIndexConfig: weaviate.configure.vectorIndex.hnsw(), + }), + }); + + await expect(collection.config.dropVectorIndex('nonexistent')).rejects.toThrow( + 'The request to Weaviate failed with status code: 422 and message: {"error":[{"message":"not found: vector index \\"nonexistent\\" not found in class \\"TestDropNonExistentNamedVectorIndex\\""}]}' + ); + + // Ensure existing vector index is still intact + const config = await collection.config.get(); + expect(config.vectorizers.existing.indexType).toEqual('hnsw'); + }); + + it('should drop named vector index from a collection with generics', async () => { + type TestDropVectorIndexVectors = { + one: number[]; + two: number[]; + }; + const collectionName = 'TestDropNamedVectorIndex'; + const collection = await client.collections.create({ + name: collectionName, + vectorizers: [ + weaviate.configure.vectors.selfProvided({ + name: 'one', + vectorIndexConfig: weaviate.configure.vectorIndex.hnsw(), + }), + weaviate.configure.vectors.selfProvided({ + name: 'two', + vectorIndexConfig: weaviate.configure.vectorIndex.hnsw(), + }), + ], + }); + + let config = await collection.config.get(); + expect(config.vectorizers.one.indexType).toEqual('hnsw'); + expect(config.vectorizers.two.indexType).toEqual('hnsw'); + + await collection.config.dropVectorIndex('one'); + + config = await collection.config.get(); + expect(config.vectorizers.one.indexType).toEqual('none'); + expect(config.vectorizers.two.indexType).toEqual('hnsw'); + }); + }); + requireAtLeast(1, 35, 0).it('should create and update Object TTL configuration', async () => { const collectionName = 'TestObjectTTL'; const collection = await client.collections.create({