From dae085a05c19920069a8c0344744c16966be20a0 Mon Sep 17 00:00:00 2001 From: Tommy Smith Date: Thu, 12 Jun 2025 10:01:04 +0100 Subject: [PATCH 1/2] Add client-side logic allowing to update property descriptions --- .github/workflows/main.yaml | 8 ++++---- src/collections/config/classes.ts | 17 ++++++++++++++++- src/collections/config/index.ts | 6 +++--- src/collections/config/integration.test.ts | 12 ++++++++++-- src/collections/config/types/index.ts | 9 ++++++++- 5 files changed, 41 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 335f89dd..2d34792e 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -10,10 +10,10 @@ env: WEAVIATE_124: 1.24.26 WEAVIATE_125: 1.25.34 WEAVIATE_126: 1.26.17 - WEAVIATE_127: 1.27.15 - WEAVIATE_128: 1.28.11 - WEAVIATE_129: 1.29.1 - WEAVIATE_130: 1.30.1 + WEAVIATE_127: 1.27.27 + WEAVIATE_128: 1.28.16 + WEAVIATE_129: 1.29.8 + WEAVIATE_130: 1.30.7 WEAVIATE_131: 1.31.0 concurrency: diff --git a/src/collections/config/classes.ts b/src/collections/config/classes.ts index 7c7fdc65..a8524de9 100644 --- a/src/collections/config/classes.ts +++ b/src/collections/config/classes.ts @@ -23,6 +23,7 @@ import { GenerativeConfig, GenerativeSearch, ModuleConfig, + PropertyDescriptionsUpdate, Reranker, RerankerConfig, VectorIndexType, @@ -32,10 +33,12 @@ export class MergeWithExisting { static schema( current: WeaviateClass, supportsNamedVectors: boolean, - update?: CollectionConfigUpdate + update?: CollectionConfigUpdate ): WeaviateClass { if (update === undefined) return current; if (update.description !== undefined) current.description = update.description; + if (update.propertyDescriptions !== undefined) + current.properties = MergeWithExisting.properties(current.properties, update.propertyDescriptions); if (update.generative !== undefined) current.moduleConfig = MergeWithExisting.generative(current.moduleConfig, update.generative); if (update.invertedIndex !== undefined) @@ -74,6 +77,18 @@ export class MergeWithExisting { return current; } + static properties( + current: WeaviateClass['properties'], + update: PropertyDescriptionsUpdate + ): WeaviateClass['properties'] { + if (current === undefined) throw Error('Properties are missing from the class schema.'); + if (current.length === 0) return current; + return current.map((property) => ({ + ...property, + description: update[property.name!] ?? property.description, + })); + } + static generative( current: WeaviateModuleConfig, update: ModuleConfig diff --git a/src/collections/config/index.ts b/src/collections/config/index.ts index ee982d3f..e03533af 100644 --- a/src/collections/config/index.ts +++ b/src/collections/config/index.ts @@ -87,7 +87,7 @@ const config = ( ) ).then(() => this.getShards()); }, - update: (config?: CollectionConfigUpdate) => { + update: (config?: CollectionConfigUpdate) => { return getRaw() .then(async (current) => MergeWithExisting.schema( @@ -164,10 +164,10 @@ export interface Config { * * Use the `weaviate.classes.Reconfigure` class to generate the necessary configuration objects for this method. * - * @param {CollectionConfigUpdate} [config] The configuration to update. Only a subset of the actual collection configuration can be updated. + * @param {CollectionConfigUpdate} [config] The configuration to update. Only a subset of the actual collection configuration can be updated. * @returns {Promise} A promise that resolves when the collection has been updated. */ - update: (config?: CollectionConfigUpdate) => Promise; + update: (config?: CollectionConfigUpdate) => Promise; } export class VectorIndex { diff --git a/src/collections/config/integration.test.ts b/src/collections/config/integration.test.ts index 2e63b8bb..868e3332 100644 --- a/src/collections/config/integration.test.ts +++ b/src/collections/config/integration.test.ts @@ -511,7 +511,7 @@ describe('Testing of the collection.config namespace', () => { expect(notUpdated?.status).toEqual('READY'); }); - it('should be able update the config of a collection', async () => { + it.only('should be able update the config of a collection', async () => { const collectionName = 'TestCollectionConfigUpdate'; const collection = await client.collections.create({ name: collectionName, @@ -523,8 +523,16 @@ describe('Testing of the collection.config namespace', () => { ], vectorizers: weaviate.configure.vectorizer.none(), }); + const supportsUpdatingPropertyDescriptions = await client + .getWeaviateVersion() + .then((ver) => ver.isAtLeast(1, 27, 0)); const config = await collection.config .update({ + propertyDescriptions: supportsUpdatingPropertyDescriptions + ? { + testProp: 'This is a test property', + } + : undefined, vectorizers: weaviate.reconfigure.vectorizer.update({ vectorIndexConfig: weaviate.reconfigure.vectorIndex.hnsw({ quantizer: weaviate.reconfigure.vectorIndex.quantizer.pq(), @@ -539,7 +547,7 @@ describe('Testing of the collection.config namespace', () => { { name: 'testProp', dataType: 'text', - description: undefined, + description: supportsUpdatingPropertyDescriptions ? 'This is a test property' : undefined, indexRangeFilters: false, indexSearchable: true, indexFilterable: true, diff --git a/src/collections/config/types/index.ts b/src/collections/config/types/index.ts index 04630b1c..8936002e 100644 --- a/src/collections/config/types/index.ts +++ b/src/collections/config/types/index.ts @@ -104,8 +104,15 @@ export type CollectionConfig = { vectorizers: VectorConfig; }; -export type CollectionConfigUpdate = { +export type PropertyDescriptionsUpdate = T extends undefined + ? Record + : { + [Property in keyof T]: string; + }; + +export type CollectionConfigUpdate = { description?: string; + propertyDescriptions?: PropertyDescriptionsUpdate; generative?: ModuleConfig; invertedIndex?: InvertedIndexConfigUpdate; multiTenancy?: MultiTenancyConfigUpdate; From 8909b12e0705442b2f73d616c50f22c91e067f11 Mon Sep 17 00:00:00 2001 From: Tommy Smith Date: Thu, 12 Jun 2025 10:04:10 +0100 Subject: [PATCH 2/2] Add second property to test to verify not updating the descr --- src/collections/config/integration.test.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/collections/config/integration.test.ts b/src/collections/config/integration.test.ts index 868e3332..ead96726 100644 --- a/src/collections/config/integration.test.ts +++ b/src/collections/config/integration.test.ts @@ -520,6 +520,10 @@ describe('Testing of the collection.config namespace', () => { name: 'testProp', dataType: 'text', }, + { + name: 'testProp2', + dataType: 'text', + }, ], vectorizers: weaviate.configure.vectorizer.none(), }); @@ -556,6 +560,18 @@ describe('Testing of the collection.config namespace', () => { nestedProperties: undefined, tokenization: 'word', }, + { + name: 'testProp2', + dataType: 'text', + description: undefined, + indexRangeFilters: false, + indexSearchable: true, + indexFilterable: true, + indexInverted: false, + vectorizerConfig: undefined, + nestedProperties: undefined, + tokenization: 'word', + }, ]); expect(config.generative).toBeUndefined(); expect(config.reranker).toBeUndefined();