fix: milvus (#3004)

This commit is contained in:
Finley Ge
2024-10-28 16:06:08 +08:00
committed by GitHub
parent 78a85bf847
commit 4e3d817b63

View File

@@ -13,6 +13,7 @@ import type {
} from '../controller.d'; } from '../controller.d';
import { delay } from '@fastgpt/global/common/system/utils'; import { delay } from '@fastgpt/global/common/system/utils';
import { addLog } from '../../../common/system/log'; import { addLog } from '../../../common/system/log';
import { customNanoid } from '@fastgpt/global/common/string/tools';
export class MilvusCtrl { export class MilvusCtrl {
constructor() {} constructor() {}
@@ -63,7 +64,7 @@ export class MilvusCtrl {
name: 'id', name: 'id',
data_type: DataType.Int64, data_type: DataType.Int64,
is_primary_key: true, is_primary_key: true,
autoID: true autoID: false // disable auto id, and we need to set id in insert
}, },
{ {
name: 'vector', name: 'vector',
@@ -127,11 +128,21 @@ export class MilvusCtrl {
const client = await this.getClient(); const client = await this.getClient();
const { teamId, datasetId, collectionId, vector, retry = 3 } = props; const { teamId, datasetId, collectionId, vector, retry = 3 } = props;
const generateId = () => {
// in js, the max safe integer is 2^53 - 1: 9007199254740991
// so we can generate a random number between 1-8 as the first digit
// and the rest 15 digits can be random
const firstDigit = customNanoid('12345678', 1);
const restDigits = customNanoid('1234567890', 15);
return Number(`${firstDigit}${restDigits}`);
};
const id = generateId();
try { try {
const result = await client.insert({ const result = await client.insert({
collection_name: DatasetVectorTableName, collection_name: DatasetVectorTableName,
data: [ data: [
{ {
id,
vector, vector,
teamId: String(teamId), teamId: String(teamId),
datasetId: String(datasetId), datasetId: String(datasetId),