feat(Milvus Vector Store Node): Add support for the Milvus vector db (#14404)

This commit is contained in:
Yiorgis Gozadinos
2025-04-08 14:34:40 +02:00
committed by GitHub
parent ad6c83afd4
commit 048b9d7589
8 changed files with 244 additions and 10 deletions

View File

@@ -0,0 +1,96 @@
import { Milvus } from '@langchain/community/vectorstores/milvus';
import type { MilvusLibArgs } from '@langchain/community/vectorstores/milvus';
import { MilvusClient } from '@zilliz/milvus2-sdk-node';
import type { INodeProperties } from 'n8n-workflow';
import { createVectorStoreNode } from '../shared/createVectorStoreNode/createVectorStoreNode';
import { milvusCollectionsSearch } from '../shared/createVectorStoreNode/methods/listSearch';
import { milvusCollectionRLC } from '../shared/descriptions';
const sharedFields: INodeProperties[] = [milvusCollectionRLC];
const insertFields: INodeProperties[] = [
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add Option',
default: {},
options: [
{
displayName: 'Clear Collection',
name: 'clearCollection',
type: 'boolean',
default: false,
description: 'Whether to clear the collection before inserting new data',
},
],
},
];
export class VectorStoreMilvus extends createVectorStoreNode<Milvus>({
meta: {
displayName: 'Milvus Vector Store',
name: 'vectorStoreMilvus',
description: 'Work with your data in Milvus Vector Store',
icon: { light: 'file:milvus-icon-black.svg', dark: 'file:milvus-icon-white.svg' },
docsUrl:
'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoremilvus/',
credentials: [
{
name: 'milvusApi',
required: true,
},
],
operationModes: ['load', 'insert', 'retrieve', 'retrieve-as-tool'],
},
methods: { listSearch: { milvusCollectionsSearch } },
sharedFields,
insertFields,
async getVectorStoreClient(context, _filter, embeddings, itemIndex): Promise<Milvus> {
const collection = context.getNodeParameter('milvusCollection', itemIndex, '', {
extractValue: true,
}) as string;
const credentials = await context.getCredentials<{
baseUrl: string;
username: string;
password: string;
}>('milvusApi');
const config: MilvusLibArgs = {
url: credentials.baseUrl,
username: credentials.username,
password: credentials.password,
collectionName: collection,
};
return await Milvus.fromExistingCollection(embeddings, config);
},
async populateVectorStore(context, embeddings, documents, itemIndex): Promise<void> {
const collection = context.getNodeParameter('milvusCollection', itemIndex, '', {
extractValue: true,
}) as string;
const options = context.getNodeParameter('options', itemIndex, {}) as {
clearCollection?: boolean;
};
const credentials = await context.getCredentials<{
baseUrl: string;
username: string;
password: string;
}>('milvusApi');
const config: MilvusLibArgs = {
url: credentials.baseUrl,
username: credentials.username,
password: credentials.password,
collectionName: collection,
};
if (options.clearCollection) {
const client = new MilvusClient({
address: credentials.baseUrl,
token: `${credentials.username}:${credentials.password}`,
});
await client.dropCollection({ collection_name: collection });
}
await Milvus.fromDocuments(documents, embeddings, config);
},
}) {}

View File

@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360"><title>milvus-icon-black</title><path d="M169.11689,299.04939c-27.78535-.02915-51.298-8.31411-72.45031-23.69338a122.33707,122.33707,0,0,1-14.00922-12.00616q-16.556-16.35613-33.14895-32.67482Q35.31712,216.704,21.10726,202.7519c-4.27753-4.20375-8.581-8.38131-12.83638-12.60737-5.78529-5.74539-5.692-12.21736.17135-17.91294,4.35916-4.23447,8.6808-8.50759,13.01531-12.76743q21.09033-20.727,42.18351-41.45112c7.82349-7.66748,15.53733-15.458,23.59542-22.87264A117.61725,117.61725,0,0,1,142.926,66.46075,112.79714,112.79714,0,0,1,167.7708,63.678c27.822.22006,53.14231,8.0315,75.21837,25.35039a117.49179,117.49179,0,0,1,33.56725,40.74071,111.30862,111.30862,0,0,1,11.18191,37.59258c3.75648,35.37535-6.093,66.46091-30.10087,92.86236a114.32952,114.32952,0,0,1-57.75872,34.79075A132.31853,132.31853,0,0,1,169.11689,299.04939Zm5.35425-31.43461a85.592,85.592,0,0,0,8.90555-.52289c1.86733-.18941,3.736-.42361,5.58158-.7604,22.43092-4.09372,40.60221-15.4505,54.49679-33.26538,13.51833-17.33245,18.827-37.40452,17.16875-59.24969a82.75341,82.75341,0,0,0-9.27492-31.89563c-9.21938-17.8418-23.47591-30.41362-41.44061-38.92072-16.12138-7.6342-33.07061-9.547-50.63693-6.8248a85.52038,85.52038,0,0,0-47.48221,23.39486c-12.62025,12.19885-25.1024,24.54066-37.63746,36.82758-6.28192,6.15757-12.51006,12.37048-18.83189,18.48667-4.04633,3.91467-4.21333,8.6494-.20763,12.6018q11.8256,11.66819,23.69873,23.28819c10.60865,10.42576,21.17268,20.89736,31.83058,31.27252C128.07334,259.01635,148.957,267.6,174.47114,267.61478Z"/><path d="M357.01654,180.71583a12.11267,12.11267,0,0,1-3.67773,9.07927q-16.50428,16.58232-33.07758,33.09591c-1.20808,1.20715-2.42168,1.44863-3.67166.79033-1.35017-.71105-1.82827-1.79263-1.442-3.56058a187.7592,187.7592,0,0,0,3.66284-23.911,178.77219,178.77219,0,0,0,.42091-21.92036,170.04764,170.04764,0,0,0-3.96975-31.1,3.757,3.757,0,0,1,.24665-3.12677,2.86044,2.86044,0,0,1,4.014-.76856,9.243,9.243,0,0,1,1.2578,1.10625q15.99768,15.98621,31.98832,31.97946C355.28369,174.89374,357.02471,177.76063,357.01654,180.71583Z"/><path d="M232.52066,181.32156a58.91788,58.91788,0,0,1-59.06395,59.10475c-34.72229-.0744-59.571-28.74548-58.99573-60.0188a59.03419,59.03419,0,0,1,118.05968.91405Z"/></svg>

After

Width:  |  Height:  |  Size: 2.2 KiB

View File

@@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 360 360"><defs><style>.cls-1{fill:#fff;}</style></defs><title>milvus-icon-white</title><path class="cls-1" d="M168.50983,63.3293c31.95671.507,59.93559,11.11286,83.27686,33.18535,18.7006,17.68407,30.22667,39.32512,34.81328,64.64452A105.32115,105.32115,0,0,1,288.30948,182.05c-.56967,28.47039-9.94153,53.66667-28.65343,75.19713-18.13667,20.86872-40.90888,34.11493-68.05469,39.10222-36.61066,6.7263-69.82614-1.44613-99.22656-24.47337-6.10735-4.78341-11.40667-10.44927-16.92918-15.86568q-17.83359-17.49069-35.625-35.0246Q23.68152,205.12557,7.53535,189.27287c-4.99811-4.92643-5.00166-11.76177-.00618-16.68775q16.58239-16.35193,33.222-32.64579c10.415-10.22513,20.7782-20.50417,31.27381-30.64606,6.968-6.73308,13.5621-13.8667,21.20515-19.88878a119.68976,119.68976,0,0,1,51.34517-23.68667,121.162,121.162,0,0,1,23.93459-2.38869Zm92.371,117.69085a91.99822,91.99822,0,0,0-1.48906-15.09071c-4.6589-24.42132-17.48944-43.49544-38.23938-56.98664-20.01283-13.01188-42.00792-17.05568-65.46628-12.61428a85.61952,85.61952,0,0,0-44.01862,22.6468c-8.21582,7.84726-16.269,15.86505-24.38163,23.82013q-16.31332,15.99666-32.59837,32.0219c-3.75,3.69749-3.73394,8.52908-.01266,12.20989,5.32758,5.2695,10.69285,10.50085,16.03635,15.75429q19.54138,19.21189,39.08246,38.424,28.33431,27.75336,67.98,25.94035a83.03279,83.03279,0,0,0,39.17421-11.52729c28.23729-16.81519,42.66039-41.87957,43.93305-74.59841Zm58.23612-.07522a171.37566,171.37566,0,0,0-4.09075-38.11425,11.73723,11.73723,0,0,1-.20111-1.1565,2.63478,2.63478,0,0,1,1.27481-2.74752,2.67092,2.67092,0,0,1,3.16194.02147,9.13711,9.13711,0,0,1,1.18864,1.0856q16.15512,16.14834,32.305,32.30226c5.30658,5.3075,5.2967,12.06515-.02255,17.38455q-16.09957,16.10016-32.1997,32.19985c-.277.27695-.54682.56179-.83445.82717a2.73085,2.73085,0,0,1-3.50192.44023,2.6834,2.6834,0,0,1-1.351-3.11577c1.13192-5.20587,2.10232-10.43969,2.798-15.72573a164.22388,164.22388,0,0,0,1.46944-18.85586c.0238-1.5147.00355-3.03034.00355-4.54551Z"/><path class="cls-1" d="M232.20625,180.965a70.48931,70.48931,0,1,0-.00015,0Z"/></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -1,5 +1,6 @@
import { Pinecone } from '@pinecone-database/pinecone';
import { QdrantClient } from '@qdrant/js-client-rest';
import { MilvusClient } from '@zilliz/milvus2-sdk-node';
import { ApplicationError, type IDataObject, type ILoadOptionsFunctions } from 'n8n-workflow';
export async function pineconeIndexSearch(this: ILoadOptionsFunctions) {
@@ -67,3 +68,25 @@ export async function qdrantCollectionsSearch(this: ILoadOptionsFunctions) {
return { results };
}
export async function milvusCollectionsSearch(this: ILoadOptionsFunctions) {
const credentials = await this.getCredentials<{
baseUrl: string;
username: string;
password: string;
}>('milvusApi');
const client = new MilvusClient({
address: credentials.baseUrl,
token: `${credentials.username}:${credentials.password}`,
});
const response = await client.listCollections();
const results = response.data.map((collection) => ({
name: collection.name,
value: collection.name,
}));
return { results };
}

View File

@@ -68,3 +68,26 @@ export const qdrantCollectionRLC: INodeProperties = {
},
],
};
export const milvusCollectionRLC: INodeProperties = {
displayName: 'Milvus Collection',
name: 'milvusCollection',
type: 'resourceLocator',
default: { mode: 'list', value: '' },
required: true,
modes: [
{
displayName: 'From List',
name: 'list',
type: 'list',
typeOptions: {
searchListMethod: 'milvusCollectionsSearch',
},
},
{
displayName: 'ID',
name: 'id',
type: 'string',
},
],
};