|
1 | | -import { describe, it, expect, vi, beforeEach } from "vitest"; |
| 1 | +import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; |
2 | 2 | import type { MockedFunction } from "vitest"; |
3 | 3 | import { VectorSearchEmbeddingsManager } from "../../../../src/common/search/vectorSearchEmbeddingsManager.js"; |
4 | 4 | import type { |
@@ -411,20 +411,65 @@ describe("VectorSearchEmbeddingsManager", () => { |
411 | 411 | ); |
412 | 412 | }); |
413 | 413 |
|
414 | | - describe("when atlas search is not available", () => { |
| 414 | + describe("assertVectorSearchIndexExists", () => { |
415 | 415 | beforeEach(() => { |
416 | 416 | embeddings = new VectorSearchEmbeddingsManager( |
417 | 417 | embeddingValidationEnabled, |
418 | 418 | connectionManager, |
419 | 419 | new Map(), |
420 | 420 | getMockedEmbeddingsProvider |
421 | 421 | ); |
| 422 | + }); |
| 423 | + |
| 424 | + afterEach(() => { |
| 425 | + provider.getSearchIndexes.mockReset(); |
| 426 | + }); |
| 427 | + |
| 428 | + it("does not throw an exception when index is available for path", async () => { |
| 429 | + provider.getSearchIndexes.mockResolvedValue([ |
| 430 | + { |
| 431 | + id: "65e8c766d0450e3e7ab9855f", |
| 432 | + name: "vector-search-test", |
| 433 | + type: "vectorSearch", |
| 434 | + status: "READY", |
| 435 | + queryable: true, |
| 436 | + latestDefinition: { |
| 437 | + fields: [ |
| 438 | + { |
| 439 | + type: "vector", |
| 440 | + path: embeddingToGenerate.path, |
| 441 | + numDimensions: 1024, |
| 442 | + similarity: "euclidean", |
| 443 | + }, |
| 444 | + ], |
| 445 | + }, |
| 446 | + }, |
| 447 | + ]); |
| 448 | + await expect( |
| 449 | + embeddings.assertVectorSearchIndexExists({ |
| 450 | + database, |
| 451 | + collection, |
| 452 | + path: embeddingToGenerate.path, |
| 453 | + }) |
| 454 | + ).resolves.not.toThrowError(); |
| 455 | + }); |
422 | 456 |
|
| 457 | + it("throws an exception when atlas search is not available", async () => { |
423 | 458 | provider.getSearchIndexes.mockRejectedValue(new Error()); |
| 459 | + await expect( |
| 460 | + embeddings.assertVectorSearchIndexExists({ |
| 461 | + database, |
| 462 | + collection, |
| 463 | + path: embeddingToGenerate.path, |
| 464 | + }) |
| 465 | + ).rejects.toThrowError(); |
424 | 466 | }); |
425 | 467 |
|
426 | | - it("throws an exception", async () => { |
427 | | - await expect(embeddings.generateEmbeddings(embeddingToGenerate)).rejects.toThrowError(); |
| 468 | + it("throws an exception when no index is available for path", async () => { |
| 469 | + provider.getSearchIndexes.mockResolvedValue([]); |
| 470 | + await expect( |
| 471 | + embeddings.assertVectorSearchIndexExists({ database, collection, path: embeddingToGenerate.path }) |
| 472 | + ).rejects.toThrowError(); |
428 | 473 | }); |
429 | 474 | }); |
430 | 475 |
|
@@ -459,12 +504,6 @@ describe("VectorSearchEmbeddingsManager", () => { |
459 | 504 | ); |
460 | 505 | }); |
461 | 506 |
|
462 | | - describe("when no index is available for path", () => { |
463 | | - it("throws an exception", async () => { |
464 | | - await expect(embeddings.generateEmbeddings(embeddingToGenerate)).rejects.toThrowError(); |
465 | | - }); |
466 | | - }); |
467 | | - |
468 | 507 | describe("when index is available on path", () => { |
469 | 508 | beforeEach(() => { |
470 | 509 | provider.getSearchIndexes.mockResolvedValue([ |
|
0 commit comments