2023-06-08 06:31:35 +02:00
|
|
|
function getVectorDbClass() {
|
|
|
|
const vectorSelection = process.env.VECTOR_DB || "pinecone";
|
|
|
|
switch (vectorSelection) {
|
|
|
|
case "pinecone":
|
2023-08-04 23:56:27 +02:00
|
|
|
const { Pinecone } = require("../vectorDbProviders/pinecone");
|
2023-06-08 06:31:35 +02:00
|
|
|
return Pinecone;
|
|
|
|
case "chroma":
|
2023-08-04 23:56:27 +02:00
|
|
|
const { Chroma } = require("../vectorDbProviders/chroma");
|
2023-06-08 06:31:35 +02:00
|
|
|
return Chroma;
|
2023-06-09 03:40:29 +02:00
|
|
|
case "lancedb":
|
2023-08-04 23:56:27 +02:00
|
|
|
const { LanceDb } = require("../vectorDbProviders/lance");
|
2023-06-09 03:40:29 +02:00
|
|
|
return LanceDb;
|
2023-08-09 03:02:30 +02:00
|
|
|
case "weaviate":
|
|
|
|
const { Weaviate } = require("../vectorDbProviders/weaviate");
|
|
|
|
return Weaviate;
|
2023-08-16 00:26:44 +02:00
|
|
|
case "qdrant":
|
|
|
|
const { QDrant } = require("../vectorDbProviders/qdrant");
|
|
|
|
return QDrant;
|
2023-06-08 06:31:35 +02:00
|
|
|
default:
|
2023-06-08 22:13:48 +02:00
|
|
|
throw new Error("ENV: No VECTOR_DB value found in environment!");
|
2023-06-08 06:31:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-04 23:56:27 +02:00
|
|
|
function getLLMProvider() {
|
|
|
|
const vectorSelection = process.env.LLM_PROVIDER || "openai";
|
|
|
|
switch (vectorSelection) {
|
|
|
|
case "openai":
|
2023-10-30 23:44:03 +01:00
|
|
|
const { OpenAiLLM } = require("../AiProviders/openAi");
|
|
|
|
return new OpenAiLLM();
|
2023-08-04 23:56:27 +02:00
|
|
|
case "azure":
|
2023-10-30 23:44:03 +01:00
|
|
|
const { AzureOpenAiLLM } = require("../AiProviders/azureOpenAi");
|
|
|
|
return new AzureOpenAiLLM();
|
|
|
|
case "anthropic":
|
|
|
|
const { AnthropicLLM } = require("../AiProviders/anthropic");
|
|
|
|
const embedder = getEmbeddingEngineSelection();
|
|
|
|
return new AnthropicLLM(embedder);
|
2023-08-04 23:56:27 +02:00
|
|
|
default:
|
|
|
|
throw new Error("ENV: No LLM_PROVIDER value found in environment!");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-30 23:44:03 +01:00
|
|
|
function getEmbeddingEngineSelection() {
|
|
|
|
const engineSelection = process.env.EMBEDDING_ENGINE;
|
|
|
|
switch (engineSelection) {
|
|
|
|
case "openai":
|
|
|
|
const { OpenAiEmbedder } = require("../../EmbeddingEngines/openAi");
|
|
|
|
return new OpenAiEmbedder();
|
|
|
|
case "azure":
|
|
|
|
const {
|
|
|
|
AzureOpenAiEmbedder,
|
|
|
|
} = require("../../EmbeddingEngines/azureOpenAi");
|
|
|
|
return new AzureOpenAiEmbedder();
|
|
|
|
default:
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-08 22:13:48 +02:00
|
|
|
function toChunks(arr, size) {
|
|
|
|
return Array.from({ length: Math.ceil(arr.length / size) }, (_v, i) =>
|
|
|
|
arr.slice(i * size, i * size + size)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-08 06:31:35 +02:00
|
|
|
module.exports = {
|
2023-10-30 23:44:03 +01:00
|
|
|
getEmbeddingEngineSelection,
|
2023-06-08 06:31:35 +02:00
|
|
|
getVectorDbClass,
|
2023-08-04 23:56:27 +02:00
|
|
|
getLLMProvider,
|
2023-06-08 22:13:48 +02:00
|
|
|
toChunks,
|
2023-06-08 06:31:35 +02:00
|
|
|
};
|