MCPcopy
hub / github.com/labring/FastGPT / insertDatasetDataVector

Function insertDatasetDataVector

packages/service/common/vectorDB/controller.ts:116–157  ·  view source on GitHub ↗
({
  model,
  inputs,
  ...props
}: Omit<InsertVectorControllerPropsType, 'vectors'> & {
  inputs: DatasetVectorInput[];
  model: EmbeddingModelItemType;
})

Source from the content-addressed store, hash-verified

114 * 传入 string 时保持旧行为,默认按文本生成 embedding。
115 */
116export const insertDatasetDataVector = async ({
117 model,
118 inputs,
119 ...props
120}: Omit<InsertVectorControllerPropsType, 'vectors'> & {
121 inputs: DatasetVectorInput[];
122 model: EmbeddingModelItemType;
123}) => {
124 if (inputs.length === 0) {
125 return {
126 tokens: 0,
127 insertIds: []
128 };
129 }
130
131 const embeddingInputs = inputs.map((input) =>
132 typeof input === 'string'
133 ? {
134 type: 'text' as const,
135 input
136 }
137 : input
138 );
139 const { vectors, tokens } = await getVectors({
140 model,
141 inputs: embeddingInputs,
142 type: 'db'
143 });
144 const { insertIds } = await retryFn(() =>
145 Vector.insert({
146 ...props,
147 vectors
148 })
149 );
150
151 await teamVectorCache.invalidate(props.teamId);
152
153 return {
154 tokens,
155 insertIds
156 };
157};
158
159export const deleteDatasetDataVector: VectorControllerType['delete'] = async (props) => {
160 const result = await retryFn(() => Vector.delete(props));

Callers 2

controller.test.tsFile · 0.90
insertIndexVectorIdsMethod · 0.90

Calls 5

getVectorsFunction · 0.90
retryFnFunction · 0.90
invalidateMethod · 0.80
insertMethod · 0.65
mapMethod · 0.45

Tested by

no test coverage detected