({
model,
inputs,
...props
}: Omit<InsertVectorControllerPropsType, 'vectors'> & {
inputs: DatasetVectorInput[];
model: EmbeddingModelItemType;
})
| 114 | * 传入 string 时保持旧行为,默认按文本生成 embedding。 |
| 115 | */ |
| 116 | export 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 | |
| 159 | export const deleteDatasetDataVector: VectorControllerType['delete'] = async (props) => { |
| 160 | const result = await retryFn(() => Vector.delete(props)); |
no test coverage detected