Files
template-app/test/knowledge-vector-store.test.ts
T

53 lines
2.7 KiB
TypeScript

// SPDX-License-Identifier: LicenseRef-ConusAI-Template-1.0
// Where the knowledge module's vectors backend keeps its vectors (decision 2026-10-25): a linked
// Qdrant, or pgvector when chosen explicitly, and otherwise no store at all. pgvector is never the
// silent default: the platform's default managed Postgres image has no pgvector, and the migrate
// job of a fresh app must not stop on `extension "vector" is not available` before anyone asked for
// document AI. The migrate job and the readiness probe read the same decision.
import {
KNOWLEDGE_VECTOR_STORE_VAR,
NO_VECTOR_STORE_REASON,
vectorStoreMigrationName,
vectorStoreOf,
} from "@app/config"
import { describe, expect, it } from "vitest"
import { vectorStoreMigration } from "../apps/worker/src/migrations.js"
const QDRANT = { QDRANT_URL: "http://qdrant.internal:6333" }
describe("the knowledge vector store", () => {
it("is none by default, so a fresh app migrates on a Postgres without pgvector", () => {
expect(vectorStoreOf({})).toBeNull()
expect(vectorStoreMigrationName({})).toBeNull()
expect(vectorStoreMigration({})).toBeNull()
expect(NO_VECTOR_STORE_REASON).toContain(`${KNOWLEDGE_VECTOR_STORE_VAR}=pgvector`)
})
it("is the linked Qdrant when one is linked, with no vector table", () => {
expect(vectorStoreOf(QDRANT)).toBe("qdrant")
expect(vectorStoreMigrationName(QDRANT)).toBeNull()
expect(vectorStoreOf({ ...QDRANT, KNOWLEDGE_VECTOR_STORE: "qdrant" })).toBe("qdrant")
// Qdrant required but not linked: no store, never a fallback to pgvector.
expect(vectorStoreOf({ KNOWLEDGE_VECTOR_STORE: "qdrant" })).toBeNull()
expect(vectorStoreMigrationName({ KNOWLEDGE_VECTOR_STORE: "qdrant" })).toBeNull()
})
it("is pgvector only when chosen, and then the migrate job builds the table", () => {
const chosen = { KNOWLEDGE_VECTOR_STORE: " PgVector " }
expect(vectorStoreOf(chosen)).toBe("pgvector")
expect(vectorStoreMigrationName(chosen)).toBe("0006_vectors")
const migration = vectorStoreMigration({ ...chosen, VECTOR_DIMENSIONS: "8" })
expect(migration?.name).toBe("0006_vectors")
expect(migration?.statements[0]).toBe("create extension if not exists vector")
// An explicit choice wins over a linked Qdrant.
expect(vectorStoreOf({ ...QDRANT, KNOWLEDGE_VECTOR_STORE: "pgvector" })).toBe("pgvector")
})
it("has no store on the platform backend and refuses an unknown choice", () => {
expect(vectorStoreOf({ KNOWLEDGE_BACKEND: "platform", KNOWLEDGE_VECTOR_STORE: "pgvector" })).toBeNull()
expect(vectorStoreMigrationName({ KNOWLEDGE_BACKEND: "platform", ...QDRANT })).toBeNull()
expect(() => vectorStoreOf({ KNOWLEDGE_VECTOR_STORE: "sqlite" })).toThrow(KNOWLEDGE_VECTOR_STORE_VAR)
})
})