Skip to content

Commit 509317a

Browse files
committed
fix(storage): correct QueryVectorsResponse to use vectors instead of matches
1 parent 41d76bd commit 509317a

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

packages/core/storage-js/src/lib/vectors/types.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,12 @@ export interface QueryVectorsOptions {
258258

259259
/**
260260
* Response from vector similarity query
261-
* @property matches - Array of similar vectors ordered by distance
261+
* @property vectors - Array of similar vectors ordered by distance
262+
* @property distanceMetric - The distance metric used for the similarity search
262263
*/
263264
export interface QueryVectorsResponse {
264-
matches: VectorMatch[]
265+
vectors: VectorMatch[]
266+
distanceMetric?: DistanceMetric
265267
}
266268

267269
/**

packages/core/storage-js/test/mock-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ function handleQueryVectors(body: any): MockResponse {
662662
}
663663

664664
// Calculate cosine similarity (simplified mock)
665-
const matches = allVectors
665+
const vectors = allVectors
666666
.map((vector, index) => {
667667
const result: any = { key: vector.key }
668668
if (returnDistance) {
@@ -676,7 +676,7 @@ function handleQueryVectors(body: any): MockResponse {
676676

677677
return {
678678
status: 200,
679-
data: { matches },
679+
data: { vectors, distanceMetric: 'cosine' },
680680
}
681681
}
682682

packages/core/storage-js/test/vector-data-api.spec.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,10 @@ describe('VectorDataApi Integration Tests', () => {
424424
})
425425

426426
const data = assertSuccessResponse(response)
427-
expect(data.matches).toBeDefined()
428-
expect(Array.isArray(data.matches)).toBe(true)
429-
expect(data.matches.length).toBeGreaterThan(0)
430-
expect(data.matches.length).toBeLessThanOrEqual(3)
427+
expect(data.vectors).toBeDefined()
428+
expect(Array.isArray(data.vectors)).toBe(true)
429+
expect(data.vectors.length).toBeGreaterThan(0)
430+
expect(data.vectors.length).toBeLessThanOrEqual(3)
431431
})
432432

433433
it('should return vectors with distance scores', async () => {
@@ -441,8 +441,8 @@ describe('VectorDataApi Integration Tests', () => {
441441
})
442442

443443
const data = assertSuccessResponse(response)
444-
expect(data.matches[0].distance).toBeDefined()
445-
expect(typeof data.matches[0].distance).toBe('number')
444+
expect(data.vectors[0].distance).toBeDefined()
445+
expect(typeof data.vectors[0].distance).toBe('number')
446446
})
447447

448448
it('should filter by metadata', async () => {
@@ -456,10 +456,10 @@ describe('VectorDataApi Integration Tests', () => {
456456
})
457457

458458
const data = assertSuccessResponse(response)
459-
expect(data.matches.length).toBeGreaterThan(0)
459+
expect(data.vectors.length).toBeGreaterThan(0)
460460

461461
// All results should match filter
462-
for (const match of data.matches) {
462+
for (const match of data.vectors) {
463463
expect(match.metadata?.category).toBe('tech')
464464
}
465465
})
@@ -476,7 +476,7 @@ describe('VectorDataApi Integration Tests', () => {
476476

477477
const data = assertSuccessResponse(response)
478478

479-
for (const match of data.matches) {
479+
for (const match of data.vectors) {
480480
expect(match.metadata?.category).toBe('tech')
481481
expect(match.metadata?.published).toBe(true)
482482
}
@@ -491,7 +491,7 @@ describe('VectorDataApi Integration Tests', () => {
491491
})
492492

493493
const data = assertSuccessResponse(response)
494-
expect(data.matches.length).toBeLessThanOrEqual(2)
494+
expect(data.vectors.length).toBeLessThanOrEqual(2)
495495
})
496496

497497
it('should return empty matches when filter matches nothing', async () => {
@@ -504,7 +504,7 @@ describe('VectorDataApi Integration Tests', () => {
504504
})
505505

506506
const data = assertSuccessResponse(response)
507-
expect(data.matches).toEqual([])
507+
expect(data.vectors).toEqual([])
508508
})
509509

510510
it('should query without metadata in results', async () => {
@@ -518,8 +518,8 @@ describe('VectorDataApi Integration Tests', () => {
518518
})
519519

520520
const data = assertSuccessResponse(response)
521-
expect(data.matches[0].key).toBeDefined()
522-
expect(data.matches[0].metadata).toBeUndefined()
521+
expect(data.vectors[0].key).toBeDefined()
522+
expect(data.vectors[0].metadata).toBeUndefined()
523523
})
524524
})
525525

0 commit comments

Comments
 (0)