@maogo/milvus
v1.1.4
Published
midwayjs的milvus向量数据库的orm组件
Downloads
2
Readme
该组件为midayjs的milvus ORM组件,部分对应milvus版本为2.4.x
安装@maogo/milvus
$ npm i @maogo/milvus
启用组件
// src/configuration.ts
import * as milvus from '@maogo/milvus';
@Configuration({
imports: [
milvus,
{
component: info,
enabledEnvironment: ['local'],
},
],
importConfigs: [join(__dirname, './config')],
})
配置组件
// src/config/config.default.ts
import * as milvus from '@maogo/milvus';
export default {
milvus: {
dataSource: {
default: {
host: 'localhost',
port: '19530',
username: 'root',
password: '',
ssl: false,
token: '',
entities: ['entity'],
database: 'book',
},
},
},
}
创建实体类
// src/entity/book.ts
import { DataType, Column, PrimaryColumn, Entity } from '@maogo/milvus';
@Entity('Book', {
indexParams: {
field_name: 'intro',
extra_params: {
index_type: 'AUTOINDEX',
metric_type: 'L2',
},
},
})
export class Book {
@PrimaryColumn({ dataType: DataType.Int64 })
id: number;
@Column({ dataType: DataType.FloatVector, dim: 2 })
intro: string;
@Column({ dataType: DataType.VarChar, maxLength: 256 })
name: string;
}
注入实体类并实现milvus的增删改查
import { Provide } from '@midwayjs/core';
import { InjectEntityModel, Repository } from '@maogo/milvus';
import { Book } from '../entity/book';
@Provide()
export class APiService {
@InjectEntityModel(Book)
bookModel: Repository<Book>;
// 新增数据
insert() {
this.bookModel.insert({
partition_name: '', // 分区名称,不传时默认未defalut
fields_data: []
})
}
// 插入数据
insert() {
this.bookModel.insert({
partition_name: '', // 分区名称,不传时默认未defalut
fields_data: []
})
}
// 删除数据
delete() {
this.bookModel.delete({
expr: '',
partition_name: ''
})
}
// 查询数据
search() {
this.bookModel.search({})
}
// 混合搜索
hybridSearch() {
this.bookModel.hybridSearch({})
}
// 检索数据
query() {
this.bookModel.query({})
}
// 创建分区
createPartition() {
this.bookModel.createPartition({
partition_name: '', // 分区名称
})
}
}