11import Connection from '../connection/grpc.js' ;
2- import { WeaviateInvalidInputError , WeaviateUnsupportedFeatureError } from '../errors.js' ;
2+ import { WeaviateUnsupportedFeatureError } from '../errors.js' ;
33import { WeaviateClass } from '../openapi/types.js' ;
44import ClassExists from '../schema/classExists.js' ;
55import { ClassCreator , ClassDeleter , ClassGetter , SchemaGetter } from '../schema/index.js' ;
66import { DbVersionSupport } from '../utils/dbVersion.js' ;
77import collection , { Collection } from './collection/index.js' ;
8- import { classToCollection , resolveProperty , resolveReference } from './config/utils.js' ;
9- import { QuantizerGuards } from './configure/parsing.js' ;
8+ import {
9+ classToCollection ,
10+ makeVectorsConfig ,
11+ parseVectorIndex ,
12+ parseVectorizerConfig ,
13+ resolveProperty ,
14+ resolveReference ,
15+ } from './config/utils.js' ;
1016import { configGuards } from './index.js' ;
1117import {
1218 CollectionConfig ,
@@ -23,13 +29,7 @@ import {
2329 RerankerConfig ,
2430 ShardingConfigCreate ,
2531 VectorConfigCreate ,
26- VectorIndexConfigCreate ,
27- VectorIndexConfigDynamicCreate ,
28- VectorIndexConfigFlatCreate ,
29- VectorIndexConfigHNSWCreate ,
30- VectorIndexType ,
3132 Vectorizer ,
32- VectorizerConfig ,
3333 VectorizersConfigCreate ,
3434} from './types/index.js' ;
3535import { PrimitiveKeys } from './types/internal.js' ;
@@ -65,52 +65,6 @@ export type CollectionConfigCreate<TProperties = undefined, N = string> = {
6565 vectorizers ?: VectorizersConfigCreate < TProperties > ;
6666} ;
6767
68- const parseVectorIndex = ( module : ModuleConfig < VectorIndexType , VectorIndexConfigCreate > ) : any => {
69- if ( module . config === undefined ) return undefined ;
70- if ( module . name === 'dynamic' ) {
71- const { hnsw, flat, ...conf } = module . config as VectorIndexConfigDynamicCreate ;
72- return {
73- ...conf ,
74- hnsw : parseVectorIndex ( { name : 'hnsw' , config : hnsw } ) ,
75- flat : parseVectorIndex ( { name : 'flat' , config : flat } ) ,
76- } ;
77- }
78- const { quantizer, ...conf } = module . config as
79- | VectorIndexConfigFlatCreate
80- | VectorIndexConfigHNSWCreate
81- | Record < string , any > ;
82- if ( quantizer === undefined ) return conf ;
83- if ( QuantizerGuards . isBQCreate ( quantizer ) ) {
84- const { type, ...quant } = quantizer ;
85- return {
86- ...conf ,
87- bq : {
88- ...quant ,
89- enabled : true ,
90- } ,
91- } ;
92- }
93- if ( QuantizerGuards . isPQCreate ( quantizer ) ) {
94- const { type, ...quant } = quantizer ;
95- return {
96- ...conf ,
97- pq : {
98- ...quant ,
99- enabled : true ,
100- } ,
101- } ;
102- }
103- } ;
104-
105- const parseVectorizerConfig = ( config ?: VectorizerConfig ) : any => {
106- if ( config === undefined ) return { } ;
107- const { vectorizeCollectionName, ...rest } = config as any ;
108- return {
109- ...rest ,
110- vectorizeClassName : vectorizeCollectionName ,
111- } ;
112- } ;
113-
11468const collections = ( connection : Connection , dbVersionSupport : DbVersionSupport ) => {
11569 const listAll = ( ) =>
11670 new SchemaGetter ( connection )
@@ -137,43 +91,6 @@ const collections = (connection: Connection, dbVersionSupport: DbVersionSupport)
13791 moduleConfig [ config . reranker . name ] = config . reranker . config ? config . reranker . config : { } ;
13892 }
13993
140- const makeVectorsConfig = ( configVectorizers : VectorizersConfigCreate < TProperties > ) => {
141- let vectorizers : string [ ] = [ ] ;
142- const vectorsConfig : Record < string , any > = { } ;
143- const vectorizersConfig = Array . isArray ( configVectorizers )
144- ? configVectorizers
145- : [
146- {
147- ...configVectorizers ,
148- name : 'default' ,
149- } ,
150- ] ;
151- vectorizersConfig . forEach ( ( v ) => {
152- if ( v . vectorIndex . name === 'dynamic' && ! supportsDynamicVectorIndex . supports ) {
153- throw new WeaviateUnsupportedFeatureError ( supportsDynamicVectorIndex . message ) ;
154- }
155- const vectorConfig : any = {
156- vectorIndexConfig : parseVectorIndex ( v . vectorIndex ) ,
157- vectorIndexType : v . vectorIndex . name ,
158- vectorizer : { } ,
159- } ;
160- const vectorizer =
161- v . vectorizer . name === 'text2vec-azure-openai' ? 'text2vec-openai' : v . vectorizer . name ;
162- vectorizers = [ ...vectorizers , vectorizer ] ;
163- vectorConfig . vectorizer [ vectorizer ] = {
164- properties : v . properties ,
165- ...parseVectorizerConfig ( v . vectorizer . config ) ,
166- } ;
167- if ( v . name === undefined ) {
168- throw new WeaviateInvalidInputError (
169- 'vectorName is required for each vectorizer when specifying more than one vectorizer'
170- ) ;
171- }
172- vectorsConfig [ v . name ] = vectorConfig ;
173- } ) ;
174- return { vectorsConfig, vectorizers } ;
175- } ;
176-
17794 const makeLegacyVectorizer = (
17895 configVectorizers : VectorConfigCreate < PrimitiveKeys < TProperties > , undefined , string , Vectorizer >
17996 ) => {
@@ -221,7 +138,7 @@ const collections = (connection: Connection, dbVersionSupport: DbVersionSupport)
221138 let vectorizers : string [ ] = [ ] ;
222139 if ( supportsNamedVectors . supports ) {
223140 const { vectorsConfig, vectorizers : vecs } = config . vectorizers
224- ? makeVectorsConfig ( config . vectorizers )
141+ ? makeVectorsConfig ( config . vectorizers , supportsDynamicVectorIndex )
225142 : { vectorsConfig : undefined , vectorizers : [ ] } ;
226143 schema . vectorConfig = vectorsConfig ;
227144 vectorizers = [ ...vecs ] ;
0 commit comments