mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-09-11 23:03:25 +02:00
* Add chat/converstaion mode as the default chat mode Show menu for toggling options for chat/query/reset command Show chat status below input resolves #61 * remove console logs
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
function getVectorDbClass() {
|
|
const { Pinecone } = require("../vectorDbProviders/pinecone");
|
|
const { Chroma } = require("../vectorDbProviders/chroma");
|
|
const { LanceDb } = require("../vectorDbProviders/lance");
|
|
|
|
const vectorSelection = process.env.VECTOR_DB || "pinecone";
|
|
switch (vectorSelection) {
|
|
case "pinecone":
|
|
return Pinecone;
|
|
case "chroma":
|
|
return Chroma;
|
|
case "lancedb":
|
|
return LanceDb;
|
|
default:
|
|
throw new Error("ENV: No VECTOR_DB value found in environment!");
|
|
}
|
|
}
|
|
|
|
function toChunks(arr, size) {
|
|
return Array.from({ length: Math.ceil(arr.length / size) }, (_v, i) =>
|
|
arr.slice(i * size, i * size + size)
|
|
);
|
|
}
|
|
|
|
function curateSources(sources = []) {
|
|
const knownDocs = [];
|
|
const documents = [];
|
|
|
|
for (const source of sources) {
|
|
const { metadata = {} } = source;
|
|
if (
|
|
Object.keys(metadata).length > 0 &&
|
|
!knownDocs.includes(metadata.title)
|
|
) {
|
|
documents.push({ ...metadata });
|
|
knownDocs.push(metadata.title);
|
|
}
|
|
}
|
|
|
|
return documents;
|
|
}
|
|
|
|
module.exports = {
|
|
getVectorDbClass,
|
|
toChunks,
|
|
curateSources,
|
|
};
|