|
1 | 1 | /* eslint-disable @typescript-eslint/no-non-null-assertion */ |
2 | 2 | /* eslint-disable @typescript-eslint/no-non-null-asserted-optional-chain */ |
| 3 | +import { requireAtLeast } from '../../../test/version.js'; |
3 | 4 | import weaviate, { |
4 | 5 | VectorIndexConfigHNSW, |
5 | 6 | WeaviateClient, |
6 | 7 | WeaviateField, |
7 | 8 | WeaviateGenericObject, |
8 | 9 | } from '../../index.js'; |
9 | | -import { DbVersion } from '../../utils/dbVersion.js'; |
10 | 10 | import { Collection } from '../collection/index.js'; |
11 | 11 | import { MultiVectorType, SingleVectorType } from '../query/types.js'; |
12 | 12 |
|
13 | | -const only = DbVersion.fromString(`v${process.env.WEAVIATE_VERSION!}`).isAtLeast(1, 29, 0) |
14 | | - ? describe |
15 | | - : describe.skip; |
| 13 | +requireAtLeast(1, 29, 0).describe( |
| 14 | + 'Testing of the collection.query methods with a collection with multvectors', |
| 15 | + () => { |
| 16 | + let client: WeaviateClient; |
| 17 | + let collection: Collection<undefined, string, MyVectors>; |
| 18 | + const collectionName = 'TestCollectionQueryWithMultiVectors'; |
16 | 19 |
|
17 | | -only('Testing of the collection.query methods with a collection with multvectors', () => { |
18 | | - let client: WeaviateClient; |
19 | | - let collection: Collection<undefined, string, MyVectors>; |
20 | | - const collectionName = 'TestCollectionQueryWithMultiVectors'; |
| 20 | + let id1: string; |
| 21 | + let id2: string; |
21 | 22 |
|
22 | | - let id1: string; |
23 | | - let id2: string; |
| 23 | + let singleVector: SingleVectorType; |
| 24 | + let multiVector: MultiVectorType; |
24 | 25 |
|
25 | | - let singleVector: SingleVectorType; |
26 | | - let multiVector: MultiVectorType; |
| 26 | + type MyVectors = { |
| 27 | + regular: SingleVectorType; |
| 28 | + colbert: MultiVectorType; |
| 29 | + }; |
27 | 30 |
|
28 | | - type MyVectors = { |
29 | | - regular: SingleVectorType; |
30 | | - colbert: MultiVectorType; |
31 | | - }; |
| 31 | + afterAll(() => { |
| 32 | + return client.collections.delete(collectionName).catch((err) => { |
| 33 | + console.error(err); |
| 34 | + throw err; |
| 35 | + }); |
| 36 | + }); |
32 | 37 |
|
33 | | - afterAll(() => { |
34 | | - return client.collections.delete(collectionName).catch((err) => { |
35 | | - console.error(err); |
36 | | - throw err; |
| 38 | + beforeAll(async () => { |
| 39 | + client = await weaviate.connectToLocal(); |
| 40 | + collection = client.collections.use(collectionName); |
37 | 41 | }); |
38 | | - }); |
39 | | - |
40 | | - beforeAll(async () => { |
41 | | - client = await weaviate.connectToLocal(); |
42 | | - collection = client.collections.use(collectionName); |
43 | | - }); |
44 | | - |
45 | | - afterAll(() => client.collections.delete(collectionName)); |
46 | | - |
47 | | - it('should be able to create a collection including multivectors', async () => { |
48 | | - const { hnsw } = weaviate.configure.vectorIndex; |
49 | | - const { multiVector } = weaviate.configure.vectorIndex.multiVector; |
50 | | - collection = await client.collections.create({ |
51 | | - name: collectionName, |
52 | | - vectorizers: [ |
53 | | - weaviate.configure.vectorizer.none({ |
54 | | - name: 'regular', |
55 | | - }), |
56 | | - weaviate.configure.vectorizer.none({ |
57 | | - name: 'colbert', |
58 | | - vectorIndexConfig: hnsw({ |
59 | | - multiVector: multiVector(), |
| 42 | + |
| 43 | + afterAll(() => client.collections.delete(collectionName)); |
| 44 | + |
| 45 | + it('should be able to create a collection including multivectors', async () => { |
| 46 | + collection = await client.collections.create({ |
| 47 | + name: collectionName, |
| 48 | + vectorizers: [ |
| 49 | + weaviate.configure.multiVectors.selfProvided({ |
| 50 | + name: 'regular', |
60 | 51 | }), |
61 | | - }), |
62 | | - ], |
| 52 | + weaviate.configure.multiVectors.selfProvided({ |
| 53 | + name: 'colbert', |
| 54 | + }), |
| 55 | + ], |
| 56 | + }); |
63 | 57 | }); |
64 | | - }); |
65 | | - |
66 | | - it('should be able to get the config of the created collection', async () => { |
67 | | - const config = await collection.config.get(); |
68 | | - expect(config.vectorizers.regular).toBeDefined(); |
69 | | - expect(config.vectorizers.colbert).toBeDefined(); |
70 | | - expect((config.vectorizers.regular.indexConfig as VectorIndexConfigHNSW).multiVector).toBeUndefined(); |
71 | | - expect((config.vectorizers.colbert.indexConfig as VectorIndexConfigHNSW).multiVector).toBeDefined(); |
72 | | - }); |
73 | | - |
74 | | - it('should be able to insert one object with multiple multivectors', async () => { |
75 | | - id1 = await collection.data.insert({ |
76 | | - vectors: { |
77 | | - regular: [1, 2, 3, 4], |
78 | | - colbert: [ |
| 58 | + |
| 59 | + it('should be able to get the config of the created collection', async () => { |
| 60 | + const config = await collection.config.get(); |
| 61 | + expect(config.vectorizers.regular).toBeDefined(); |
| 62 | + expect(config.vectorizers.colbert).toBeDefined(); |
| 63 | + expect((config.vectorizers.regular.indexConfig as VectorIndexConfigHNSW).multiVector).toBeUndefined(); |
| 64 | + expect((config.vectorizers.colbert.indexConfig as VectorIndexConfigHNSW).multiVector).toBeDefined(); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should be able to insert one object with multiple multivectors', async () => { |
| 68 | + id1 = await collection.data.insert({ |
| 69 | + vectors: { |
| 70 | + regular: [1, 2, 3, 4], |
| 71 | + colbert: [ |
| 72 | + [1, 2], |
| 73 | + [3, 4], |
| 74 | + ], |
| 75 | + }, |
| 76 | + }); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should be able to get the inserted object with its vectors stated implicitly', async () => { |
| 80 | + const obj = await collection.query.fetchObjectById(id1, { includeVector: true }); |
| 81 | + const assert = (obj: any): obj is WeaviateGenericObject<Record<string, WeaviateField>, MyVectors> => { |
| 82 | + expect(obj).not.toBeNull(); |
| 83 | + return true; |
| 84 | + }; |
| 85 | + if (assert(obj)) { |
| 86 | + singleVector = obj.vectors.regular; |
| 87 | + multiVector = obj.vectors.colbert; |
| 88 | + expect(obj.uuid).toBe(id1); |
| 89 | + expect(obj.vectors).toBeDefined(); |
| 90 | + expect(obj.vectors.regular).toEqual([1, 2, 3, 4]); |
| 91 | + expect(obj.vectors.colbert).toEqual([ |
79 | 92 | [1, 2], |
80 | 93 | [3, 4], |
81 | | - ], |
82 | | - }, |
| 94 | + ]); |
| 95 | + } |
83 | 96 | }); |
84 | | - }); |
85 | 97 |
|
86 | | - it('should be able to get the inserted object with its vectors stated implicitly', async () => { |
87 | | - const obj = await collection.query.fetchObjectById(id1, { includeVector: true }); |
88 | | - const assert = (obj: any): obj is WeaviateGenericObject<Record<string, WeaviateField>, MyVectors> => { |
89 | | - expect(obj).not.toBeNull(); |
90 | | - return true; |
91 | | - }; |
92 | | - if (assert(obj)) { |
93 | | - singleVector = obj.vectors.regular; |
94 | | - multiVector = obj.vectors.colbert; |
95 | | - expect(obj.uuid).toBe(id1); |
96 | | - expect(obj.vectors).toBeDefined(); |
97 | | - expect(obj.vectors.regular).toEqual([1, 2, 3, 4]); |
98 | | - expect(obj.vectors.colbert).toEqual([ |
99 | | - [1, 2], |
100 | | - [3, 4], |
101 | | - ]); |
102 | | - } |
103 | | - }); |
104 | | - |
105 | | - it('should be able to get the inserted object with its vectors stated explicitly', async () => { |
106 | | - const obj = await collection.query.fetchObjectById(id1, { includeVector: ['regular', 'colbert'] }); |
107 | | - const assert = (obj: any): obj is WeaviateGenericObject<Record<string, WeaviateField>, MyVectors> => { |
108 | | - expect(obj).not.toBeNull(); |
109 | | - return true; |
110 | | - }; |
111 | | - if (assert(obj)) { |
112 | | - singleVector = obj.vectors.regular; |
113 | | - multiVector = obj.vectors.colbert; |
114 | | - expect(obj.uuid).toBe(id1); |
115 | | - expect(obj.vectors).toBeDefined(); |
116 | | - expect(obj.vectors.regular).toEqual([1, 2, 3, 4]); |
117 | | - expect(obj.vectors.colbert).toEqual([ |
118 | | - [1, 2], |
119 | | - [3, 4], |
120 | | - ]); |
121 | | - } |
122 | | - }); |
123 | | - |
124 | | - it('should be able to get the inserted object with one of its vectors', async () => { |
125 | | - const obj = await collection.query.fetchObjectById(id1, { includeVector: ['regular'] }); |
126 | | - singleVector = obj?.vectors.regular!; |
127 | | - expect(obj?.uuid).toBe(id1); |
128 | | - expect(obj?.vectors).toBeDefined(); |
129 | | - expect(obj?.vectors.regular).toEqual([1, 2, 3, 4]); |
130 | | - expect((obj?.vectors as MyVectors).colbert).toBeUndefined(); |
131 | | - }); |
132 | | - |
133 | | - it('should be able to query with hybrid for the inserted object over the single vector space', async () => { |
134 | | - const result = await collection.query.hybrid('', { |
135 | | - alpha: 1, |
136 | | - vector: singleVector, |
137 | | - targetVector: ['regular'], |
| 98 | + it('should be able to get the inserted object with its vectors stated explicitly', async () => { |
| 99 | + const obj = await collection.query.fetchObjectById(id1, { includeVector: ['regular', 'colbert'] }); |
| 100 | + const assert = (obj: any): obj is WeaviateGenericObject<Record<string, WeaviateField>, MyVectors> => { |
| 101 | + expect(obj).not.toBeNull(); |
| 102 | + return true; |
| 103 | + }; |
| 104 | + if (assert(obj)) { |
| 105 | + singleVector = obj.vectors.regular; |
| 106 | + multiVector = obj.vectors.colbert; |
| 107 | + expect(obj.uuid).toBe(id1); |
| 108 | + expect(obj.vectors).toBeDefined(); |
| 109 | + expect(obj.vectors.regular).toEqual([1, 2, 3, 4]); |
| 110 | + expect(obj.vectors.colbert).toEqual([ |
| 111 | + [1, 2], |
| 112 | + [3, 4], |
| 113 | + ]); |
| 114 | + } |
138 | 115 | }); |
139 | | - expect(result.objects.length).toBe(1); |
140 | | - expect(result.objects[0].uuid).toBe(id1); |
141 | | - }); |
142 | | - |
143 | | - it('should be able to query with hybrid for the inserted object over the multi vector space', async () => { |
144 | | - const result = await collection.query.hybrid('', { |
145 | | - alpha: 1, |
146 | | - vector: multiVector, |
147 | | - targetVector: ['colbert'], |
| 116 | + |
| 117 | + it('should be able to get the inserted object with one of its vectors', async () => { |
| 118 | + const obj = await collection.query.fetchObjectById(id1, { includeVector: ['regular'] }); |
| 119 | + singleVector = obj?.vectors.regular!; |
| 120 | + expect(obj?.uuid).toBe(id1); |
| 121 | + expect(obj?.vectors).toBeDefined(); |
| 122 | + expect(obj?.vectors.regular).toEqual([1, 2, 3, 4]); |
| 123 | + expect((obj?.vectors as MyVectors).colbert).toBeUndefined(); |
148 | 124 | }); |
149 | | - expect(result.objects.length).toBe(1); |
150 | | - expect(result.objects[0].uuid).toBe(id1); |
151 | | - }); |
152 | | - |
153 | | - it('should be able to query with hybrid for the inserted object over both spaces simultaneously', async () => { |
154 | | - const result = await collection.query.hybrid('', { |
155 | | - alpha: 1, |
156 | | - vector: { regular: singleVector, colbert: multiVector }, |
157 | | - targetVector: collection.multiTargetVector.sum(['regular', 'colbert']), |
| 125 | + |
| 126 | + it('should be able to query with hybrid for the inserted object over the single vector space', async () => { |
| 127 | + const result = await collection.query.hybrid('', { |
| 128 | + alpha: 1, |
| 129 | + vector: singleVector, |
| 130 | + targetVector: ['regular'], |
| 131 | + }); |
| 132 | + expect(result.objects.length).toBe(1); |
| 133 | + expect(result.objects[0].uuid).toBe(id1); |
158 | 134 | }); |
159 | | - expect(result.objects.length).toBe(1); |
160 | | - expect(result.objects[0].uuid).toBe(id1); |
161 | | - }); |
162 | | - |
163 | | - it('should be able to query with nearVector for the inserted object over the single vector space', async () => { |
164 | | - const result = await collection.query.nearVector(singleVector, { |
165 | | - certainty: 0.5, |
166 | | - targetVector: ['regular'], |
| 135 | + |
| 136 | + it('should be able to query with hybrid for the inserted object over the multi vector space', async () => { |
| 137 | + const result = await collection.query.hybrid('', { |
| 138 | + alpha: 1, |
| 139 | + vector: multiVector, |
| 140 | + targetVector: ['colbert'], |
| 141 | + }); |
| 142 | + expect(result.objects.length).toBe(1); |
| 143 | + expect(result.objects[0].uuid).toBe(id1); |
167 | 144 | }); |
168 | | - expect(result.objects.length).toBe(1); |
169 | | - expect(result.objects[0].uuid).toBe(id1); |
170 | | - }); |
171 | | - |
172 | | - it('should be able to query with nearVector for the inserted object over the multi vector space', async () => { |
173 | | - const result = await collection.query.nearVector(multiVector, { |
174 | | - certainty: 0.5, |
175 | | - targetVector: ['colbert'], |
| 145 | + |
| 146 | + it('should be able to query with hybrid for the inserted object over both spaces simultaneously', async () => { |
| 147 | + const result = await collection.query.hybrid('', { |
| 148 | + alpha: 1, |
| 149 | + vector: { regular: singleVector, colbert: multiVector }, |
| 150 | + targetVector: collection.multiTargetVector.sum(['regular', 'colbert']), |
| 151 | + }); |
| 152 | + expect(result.objects.length).toBe(1); |
| 153 | + expect(result.objects[0].uuid).toBe(id1); |
| 154 | + }); |
| 155 | + |
| 156 | + it('should be able to query with nearVector for the inserted object over the single vector space', async () => { |
| 157 | + const result = await collection.query.nearVector(singleVector, { |
| 158 | + certainty: 0.5, |
| 159 | + targetVector: ['regular'], |
| 160 | + }); |
| 161 | + expect(result.objects.length).toBe(1); |
| 162 | + expect(result.objects[0].uuid).toBe(id1); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should be able to query with nearVector for the inserted object over the multi vector space', async () => { |
| 166 | + const result = await collection.query.nearVector(multiVector, { |
| 167 | + certainty: 0.5, |
| 168 | + targetVector: ['colbert'], |
| 169 | + }); |
| 170 | + expect(result.objects.length).toBe(1); |
| 171 | + expect(result.objects[0].uuid).toBe(id1); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should be able to query with nearVector for the inserted object over both spaces simultaneously', async () => { |
| 175 | + const result = await collection.query.nearVector( |
| 176 | + { regular: singleVector, colbert: multiVector }, |
| 177 | + { targetVector: collection.multiTargetVector.sum(['regular', 'colbert']) } |
| 178 | + ); |
| 179 | + expect(result.objects.length).toBe(1); |
| 180 | + expect(result.objects[0].uuid).toBe(id1); |
176 | 181 | }); |
177 | | - expect(result.objects.length).toBe(1); |
178 | | - expect(result.objects[0].uuid).toBe(id1); |
179 | | - }); |
180 | | - |
181 | | - it('should be able to query with nearVector for the inserted object over both spaces simultaneously', async () => { |
182 | | - const result = await collection.query.nearVector( |
183 | | - { regular: singleVector, colbert: multiVector }, |
184 | | - { targetVector: collection.multiTargetVector.sum(['regular', 'colbert']) } |
185 | | - ); |
186 | | - expect(result.objects.length).toBe(1); |
187 | | - expect(result.objects[0].uuid).toBe(id1); |
188 | | - }); |
189 | | -}); |
| 182 | + } |
| 183 | +); |
0 commit comments