diff --git a/consts/envs.ts b/consts/envs.ts index cb45134..c4f76a2 100644 --- a/consts/envs.ts +++ b/consts/envs.ts @@ -17,6 +17,7 @@ export const MODEL_KNOWLEDGE_CUTOFF = "MODEL_KNOWLEDGE_CUTOFF"; // this env names for embedding export const EMBEDDING_POVIDER = "EMBEDDING_POVIDER"; export const EMBEDDING_MODELS = "EMBEDDING_MODELS"; +export const EMBEDDING_DIMENSION = "EMBEDDING_DIMENSION"; // the env var names of anthropic export const ANTHROPIC_API_URL = "ANTHROPIC_API_URL"; @@ -43,3 +44,5 @@ export const MODELS_MAPPING = "MODELS_MAPPING"; export const GOOGLE_API_URL = "GOOGLE_API_URL"; export const GOOGLE_API_KEY = "GOOGLE_API_KEY"; export const GOOGLE_API_VERSION = "GOOGLE_API_VERSION"; + +export const PGVECTOR_URL = "PGVECTOR_URL"; diff --git a/providers/vector_db/pgvector.ts b/providers/vector_db/pgvector.ts index 55262a7..e95a5f0 100644 --- a/providers/vector_db/pgvector.ts +++ b/providers/vector_db/pgvector.ts @@ -1,11 +1,18 @@ import { Pool, QueryArguments } from "$postgres/mod.ts"; import * as log from "$std/log/mod.ts"; - -const databaseUrl = Deno.env.get("PGVECTOR_URL")!; -const embeddingDimension = Deno.env.get("EMBEDDING_DIMENSION")!; +import { getEnv } from "$/utils/env.ts"; +import { EMBEDDING_DIMENSION, PGVECTOR_URL } from "$/consts/envs.ts"; export default class Client { - static pool = new Pool(databaseUrl, 3, true); + static pool = new Pool( + getEnv( + PGVECTOR_URL, + "postgres://postgres:postgres@localhost:5432/assistant", + ), + 5, + true, + ); + static embeddingDimension = getEnv(EMBEDDING_DIMENSION, "1536"); public static async create(vectorStoreId: string) { const sql = ` @@ -14,7 +21,7 @@ export default class Client { file_id TEXT NOT NULL, file_name TEXT NOT NULL, content TEXT NOT NULL, - embedding VECTOR(${embeddingDimension}) + embedding VECTOR(${this.embeddingDimension}) ) `; await this.query(sql);