Skip to content

Commit a40740f

Browse files
authored
Add client-side logic allowing to update property descriptions (#305)
* Add client-side logic allowing to update property descriptions * Add second property to test to verify not updating the descr
1 parent 364112b commit a40740f

File tree

5 files changed

+56
-10
lines changed

5 files changed

+56
-10
lines changed

.github/workflows/main.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ env:
1010
WEAVIATE_124: 1.24.26
1111
WEAVIATE_125: 1.25.34
1212
WEAVIATE_126: 1.26.17
13-
WEAVIATE_127: 1.27.15
14-
WEAVIATE_128: 1.28.11
15-
WEAVIATE_129: 1.29.1
16-
WEAVIATE_130: 1.30.1
13+
WEAVIATE_127: 1.27.27
14+
WEAVIATE_128: 1.28.16
15+
WEAVIATE_129: 1.29.8
16+
WEAVIATE_130: 1.30.7
1717
WEAVIATE_131: 1.31.0
1818

1919
concurrency:

src/collections/config/classes.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
GenerativeConfig,
2424
GenerativeSearch,
2525
ModuleConfig,
26+
PropertyDescriptionsUpdate,
2627
Reranker,
2728
RerankerConfig,
2829
VectorIndexType,
@@ -32,10 +33,12 @@ export class MergeWithExisting {
3233
static schema(
3334
current: WeaviateClass,
3435
supportsNamedVectors: boolean,
35-
update?: CollectionConfigUpdate
36+
update?: CollectionConfigUpdate<any>
3637
): WeaviateClass {
3738
if (update === undefined) return current;
3839
if (update.description !== undefined) current.description = update.description;
40+
if (update.propertyDescriptions !== undefined)
41+
current.properties = MergeWithExisting.properties(current.properties, update.propertyDescriptions);
3942
if (update.generative !== undefined)
4043
current.moduleConfig = MergeWithExisting.generative(current.moduleConfig, update.generative);
4144
if (update.invertedIndex !== undefined)
@@ -74,6 +77,18 @@ export class MergeWithExisting {
7477
return current;
7578
}
7679

80+
static properties(
81+
current: WeaviateClass['properties'],
82+
update: PropertyDescriptionsUpdate<any>
83+
): WeaviateClass['properties'] {
84+
if (current === undefined) throw Error('Properties are missing from the class schema.');
85+
if (current.length === 0) return current;
86+
return current.map((property) => ({
87+
...property,
88+
description: update[property.name!] ?? property.description,
89+
}));
90+
}
91+
7792
static generative(
7893
current: WeaviateModuleConfig,
7994
update: ModuleConfig<GenerativeSearch, GenerativeConfig>

src/collections/config/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const config = <T>(
8787
)
8888
).then(() => this.getShards());
8989
},
90-
update: (config?: CollectionConfigUpdate) => {
90+
update: (config?: CollectionConfigUpdate<T>) => {
9191
return getRaw()
9292
.then(async (current) =>
9393
MergeWithExisting.schema(
@@ -164,10 +164,10 @@ export interface Config<T> {
164164
*
165165
* Use the `weaviate.classes.Reconfigure` class to generate the necessary configuration objects for this method.
166166
*
167-
* @param {CollectionConfigUpdate} [config] The configuration to update. Only a subset of the actual collection configuration can be updated.
167+
* @param {CollectionConfigUpdate<T>} [config] The configuration to update. Only a subset of the actual collection configuration can be updated.
168168
* @returns {Promise<void>} A promise that resolves when the collection has been updated.
169169
*/
170-
update: (config?: CollectionConfigUpdate) => Promise<void>;
170+
update: (config?: CollectionConfigUpdate<T>) => Promise<void>;
171171
}
172172

173173
export class VectorIndex {

src/collections/config/integration.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ describe('Testing of the collection.config namespace', () => {
511511
expect(notUpdated?.status).toEqual('READY');
512512
});
513513

514-
it('should be able update the config of a collection', async () => {
514+
it.only('should be able update the config of a collection', async () => {
515515
const collectionName = 'TestCollectionConfigUpdate';
516516
const collection = await client.collections.create({
517517
name: collectionName,
@@ -520,11 +520,23 @@ describe('Testing of the collection.config namespace', () => {
520520
name: 'testProp',
521521
dataType: 'text',
522522
},
523+
{
524+
name: 'testProp2',
525+
dataType: 'text',
526+
},
523527
],
524528
vectorizers: weaviate.configure.vectorizer.none(),
525529
});
530+
const supportsUpdatingPropertyDescriptions = await client
531+
.getWeaviateVersion()
532+
.then((ver) => ver.isAtLeast(1, 27, 0));
526533
const config = await collection.config
527534
.update({
535+
propertyDescriptions: supportsUpdatingPropertyDescriptions
536+
? {
537+
testProp: 'This is a test property',
538+
}
539+
: undefined,
528540
vectorizers: weaviate.reconfigure.vectorizer.update({
529541
vectorIndexConfig: weaviate.reconfigure.vectorIndex.hnsw({
530542
quantizer: weaviate.reconfigure.vectorIndex.quantizer.pq(),
@@ -539,6 +551,18 @@ describe('Testing of the collection.config namespace', () => {
539551
{
540552
name: 'testProp',
541553
dataType: 'text',
554+
description: supportsUpdatingPropertyDescriptions ? 'This is a test property' : undefined,
555+
indexRangeFilters: false,
556+
indexSearchable: true,
557+
indexFilterable: true,
558+
indexInverted: false,
559+
vectorizerConfig: undefined,
560+
nestedProperties: undefined,
561+
tokenization: 'word',
562+
},
563+
{
564+
name: 'testProp2',
565+
dataType: 'text',
542566
description: undefined,
543567
indexRangeFilters: false,
544568
indexSearchable: true,

src/collections/config/types/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,15 @@ export type CollectionConfig = {
104104
vectorizers: VectorConfig;
105105
};
106106

107-
export type CollectionConfigUpdate = {
107+
export type PropertyDescriptionsUpdate<T> = T extends undefined
108+
? Record<string, string>
109+
: {
110+
[Property in keyof T]: string;
111+
};
112+
113+
export type CollectionConfigUpdate<T> = {
108114
description?: string;
115+
propertyDescriptions?: PropertyDescriptionsUpdate<T>;
109116
generative?: ModuleConfig<GenerativeSearch, GenerativeConfig>;
110117
invertedIndex?: InvertedIndexConfigUpdate;
111118
multiTenancy?: MultiTenancyConfigUpdate;

0 commit comments

Comments
 (0)