mirror of
https://github.com/labring/FastGPT.git
synced 2026-05-06 01:02:54 +08:00
feat: pg half vector (#6201)
This commit is contained in:
@@ -5,3 +5,22 @@ export const PG_ADDRESS = process.env.PG_URL;
|
||||
export const OCEANBASE_ADDRESS = process.env.OCEANBASE_URL;
|
||||
export const MILVUS_ADDRESS = process.env.MILVUS_ADDRESS;
|
||||
export const MILVUS_TOKEN = process.env.MILVUS_TOKEN;
|
||||
|
||||
export const VectorVQ = (() => {
|
||||
if (process.env.VECTOR_VQ_LEVEL === '32') {
|
||||
return 32;
|
||||
}
|
||||
if (process.env.VECTOR_VQ_LEVEL === '16') {
|
||||
return 16;
|
||||
}
|
||||
if (process.env.VECTOR_VQ_LEVEL === '8') {
|
||||
return 8;
|
||||
}
|
||||
if (process.env.VECTOR_VQ_LEVEL === '4') {
|
||||
return 4;
|
||||
}
|
||||
if (process.env.VECTOR_VQ_LEVEL === '2') {
|
||||
return 2;
|
||||
}
|
||||
return 32;
|
||||
})();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* pg vector crud */
|
||||
import { DatasetVectorTableName } from '../constants';
|
||||
import { DatasetVectorTableName, VectorVQ } from '../constants';
|
||||
import { PgClient, connectPg } from './controller';
|
||||
import { type PgSearchRawType } from '@fastgpt/global/core/dataset/api';
|
||||
import type { VectorControllerType } from '../type';
|
||||
@@ -9,13 +9,15 @@ import { addLog } from '../../system/log';
|
||||
export class PgVectorCtrl implements VectorControllerType {
|
||||
constructor() {}
|
||||
init = async () => {
|
||||
const isHalfVec = VectorVQ === 16;
|
||||
|
||||
try {
|
||||
await connectPg();
|
||||
await PgClient.query(`
|
||||
CREATE EXTENSION IF NOT EXISTS vector;
|
||||
CREATE TABLE IF NOT EXISTS ${DatasetVectorTableName} (
|
||||
id BIGSERIAL PRIMARY KEY,
|
||||
vector VECTOR(1536) NOT NULL,
|
||||
vector ${isHalfVec ? 'HALFVEC(1536)' : 'VECTOR(1536)'} NOT NULL,
|
||||
team_id VARCHAR(50) NOT NULL,
|
||||
dataset_id VARCHAR(50) NOT NULL,
|
||||
collection_id VARCHAR(50) NOT NULL,
|
||||
@@ -24,7 +26,7 @@ export class PgVectorCtrl implements VectorControllerType {
|
||||
`);
|
||||
|
||||
await PgClient.query(
|
||||
`CREATE INDEX CONCURRENTLY IF NOT EXISTS vector_index ON ${DatasetVectorTableName} USING hnsw (vector vector_ip_ops) WITH (m = 32, ef_construction = 128);`
|
||||
`CREATE INDEX CONCURRENTLY IF NOT EXISTS vector_index ON ${DatasetVectorTableName} USING hnsw (vector ${isHalfVec ? 'halfvec_ip_ops' : 'vector_ip_ops'}) WITH (m = 32, ef_construction = 128);`
|
||||
);
|
||||
await PgClient.query(
|
||||
`CREATE INDEX CONCURRENTLY IF NOT EXISTS team_dataset_collection_index ON ${DatasetVectorTableName} USING btree(team_id, dataset_id, collection_id);`
|
||||
|
||||
Reference in New Issue
Block a user