mirror of
https://github.com/n8n-io/n8n.git
synced 2026-11-03 23:00:11 +08:00
feat: Add connection tests to ChatHub vector store nodes (no-changelog) (#26830)
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ export class ChatHubVectorStoreQdrantApi implements ICredentialType {
|
||||
type: 'string',
|
||||
default: 'n8n_vectors',
|
||||
description:
|
||||
'The Qdrant collection to use. All users share this collection; access is scoped per user via a userId metadata field.',
|
||||
'The Qdrant collection to use. All users share this collection; access is scoped per user via a userId metadata field. The collection is created automatically if it does not exist.',
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
+37
-1
@@ -2,8 +2,11 @@ import type { PineconeStoreParams } from '@langchain/pinecone';
|
||||
import { PineconeStore } from '@langchain/pinecone';
|
||||
import { Pinecone } from '@pinecone-database/pinecone';
|
||||
import type {
|
||||
ICredentialsDecrypted,
|
||||
ICredentialTestFunctions,
|
||||
IDataObject,
|
||||
ILoadOptionsFunctions,
|
||||
INodeCredentialTestResult,
|
||||
INodeProperties,
|
||||
NodeParameterValueType,
|
||||
} from 'n8n-workflow';
|
||||
@@ -39,6 +42,35 @@ const insertFields: INodeProperties[] = [
|
||||
},
|
||||
];
|
||||
|
||||
async function chatHubVectorStorePineconeApiConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as ChatHubVectorStorePineconeApiCredentials;
|
||||
|
||||
try {
|
||||
const client = new Pinecone({ apiKey: credentials.apiKey });
|
||||
const indexes = ((await client.listIndexes()).indexes ?? []).map((i) => i.name);
|
||||
|
||||
if (!indexes.includes(credentials.pineconeIndex)) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: `Index "${credentials.pineconeIndex}" not found. Please create the index first or check the index name.`,
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message as string,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful',
|
||||
};
|
||||
}
|
||||
|
||||
async function deleteDocuments(
|
||||
this: ILoadOptionsFunctions,
|
||||
payload: IDataObject | string | undefined,
|
||||
@@ -78,12 +110,16 @@ export class ChatHubVectorStorePinecone extends createVectorStoreNode<PineconeSt
|
||||
{
|
||||
name: 'chatHubVectorStorePineconeApi',
|
||||
required: true,
|
||||
testedBy: 'chatHubVectorStorePineconeApiConnectionTest',
|
||||
},
|
||||
],
|
||||
operationModes: ['load', 'insert', 'retrieve', 'retrieve-as-tool'],
|
||||
},
|
||||
hidden: true,
|
||||
methods: { actionHandler: { deleteDocuments } },
|
||||
methods: {
|
||||
credentialTest: { chatHubVectorStorePineconeApiConnectionTest },
|
||||
actionHandler: { deleteDocuments },
|
||||
},
|
||||
sharedFields: [],
|
||||
retrieveFields,
|
||||
loadFields: retrieveFields,
|
||||
|
||||
+30
-1
@@ -2,8 +2,11 @@ import type { QdrantLibArgs } from '@langchain/qdrant';
|
||||
import { QdrantVectorStore } from '@langchain/qdrant';
|
||||
import {
|
||||
jsonParse,
|
||||
type ICredentialsDecrypted,
|
||||
type ICredentialTestFunctions,
|
||||
type IDataObject,
|
||||
type ILoadOptionsFunctions,
|
||||
type INodeCredentialTestResult,
|
||||
type NodeParameterValueType,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
@@ -36,6 +39,28 @@ async function ensurePayloadIndexes(
|
||||
}
|
||||
}
|
||||
|
||||
async function chatHubVectorStoreQdrantApiConnectionTest(
|
||||
this: ICredentialTestFunctions,
|
||||
credential: ICredentialsDecrypted,
|
||||
): Promise<INodeCredentialTestResult> {
|
||||
const credentials = credential.data as ChatHubVectorStoreQdrantApiCredentials;
|
||||
|
||||
try {
|
||||
const client = createQdrantClient(credentials);
|
||||
await client.getCollections();
|
||||
} catch (error) {
|
||||
return {
|
||||
status: 'Error',
|
||||
message: error.message as string,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
status: 'OK',
|
||||
message: 'Connection successful',
|
||||
};
|
||||
}
|
||||
|
||||
async function deleteDocuments(
|
||||
this: ILoadOptionsFunctions,
|
||||
payload: IDataObject | string | undefined,
|
||||
@@ -80,12 +105,16 @@ export class ChatHubVectorStoreQdrant extends createVectorStoreNode<QdrantVector
|
||||
{
|
||||
name: 'chatHubVectorStoreQdrantApi',
|
||||
required: true,
|
||||
testedBy: 'chatHubVectorStoreQdrantApiConnectionTest',
|
||||
},
|
||||
],
|
||||
operationModes: ['load', 'insert', 'retrieve', 'retrieve-as-tool'],
|
||||
},
|
||||
hidden: true,
|
||||
methods: { actionHandler: { deleteDocuments } },
|
||||
methods: {
|
||||
credentialTest: { chatHubVectorStoreQdrantApiConnectionTest },
|
||||
actionHandler: { deleteDocuments },
|
||||
},
|
||||
sharedFields: [],
|
||||
insertFields: [],
|
||||
loadFields: [],
|
||||
|
||||
Reference in New Issue
Block a user