mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-22 20:37:48 +00:00

Co-authored-by: Mufei <327958099@qq.com> Co-authored-by: heheer <71265218+newfish-cmyk@users.noreply.github.com>
39 lines
998 B
TypeScript
39 lines
998 B
TypeScript
/* vector crud */
|
|
import { PgVector } from './pg/class';
|
|
import { getVectorsByText } from '../../core/ai/embedding';
|
|
import { InsertVectorProps } from './controller.d';
|
|
import { VectorModelItemType } from '@fastgpt/global/core/ai/model.d';
|
|
|
|
const getVectorObj = () => {
|
|
return new PgVector();
|
|
};
|
|
|
|
export const initVectorStore = getVectorObj().init;
|
|
export const deleteDatasetDataVector = getVectorObj().delete;
|
|
export const recallFromVectorStore = getVectorObj().recall;
|
|
export const getVectorDataByTime = getVectorObj().getVectorDataByTime;
|
|
export const getVectorCountByTeamId = getVectorObj().getVectorCountByTeamId;
|
|
|
|
export const insertDatasetDataVector = async ({
|
|
model,
|
|
query,
|
|
...props
|
|
}: InsertVectorProps & {
|
|
query: string;
|
|
model: VectorModelItemType;
|
|
}) => {
|
|
const { vectors, tokens } = await getVectorsByText({
|
|
model,
|
|
input: query
|
|
});
|
|
const { insertId } = await getVectorObj().insert({
|
|
...props,
|
|
vectors
|
|
});
|
|
|
|
return {
|
|
tokens,
|
|
insertId
|
|
};
|
|
};
|