-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Qdrant Vector Store Node): Qdrant vector store support (#8080)
## Summary This PR intends to add [Qdrant](https://qdrant.tech/) as a supported vectorstore node to load and retrieve documents from in a workflow. ## Review / Merge checklist - [x] PR title and summary are descriptive. - [x] Node/credentials documentation to be updated in n8n-io/n8n-docs#1796. --------- Co-authored-by: oleg <me@olegivaniv.com> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
- Loading branch information
1 parent
ef3a577
commit 66460f6
Showing
7 changed files
with
228 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
packages/@n8n/nodes-langchain/credentials/QdrantApi.credentials.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { | ||
IAuthenticateGeneric, | ||
ICredentialTestRequest, | ||
ICredentialType, | ||
INodeProperties, | ||
} from 'n8n-workflow'; | ||
|
||
export class QdrantApi implements ICredentialType { | ||
name = 'qdrantApi'; | ||
|
||
displayName = 'QdrantApi'; | ||
|
||
documentationUrl = 'https://docs.n8n.io/integrations/builtin/credentials/qdrant/'; | ||
|
||
properties: INodeProperties[] = [ | ||
{ | ||
displayName: 'API Key', | ||
name: 'apiKey', | ||
type: 'string', | ||
typeOptions: { password: true }, | ||
required: true, | ||
default: '', | ||
}, | ||
{ | ||
displayName: 'Qdrant URL', | ||
name: 'qdrantUrl', | ||
type: 'string', | ||
required: true, | ||
default: '', | ||
}, | ||
]; | ||
|
||
authenticate: IAuthenticateGeneric = { | ||
type: 'generic', | ||
properties: { | ||
headers: { | ||
'api-key': '={{$credentials.apiKey}}', | ||
}, | ||
}, | ||
}; | ||
|
||
test: ICredentialTestRequest = { | ||
request: { | ||
baseURL: '={{$credentials.qdrantUrl}}', | ||
headers: { | ||
accept: 'application/json; charset=utf-8', | ||
}, | ||
}, | ||
}; | ||
} |
85 changes: 85 additions & 0 deletions
85
packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { type INodeProperties } from 'n8n-workflow'; | ||
import type { QdrantLibArgs } from 'langchain/vectorstores/qdrant'; | ||
import { QdrantVectorStore } from 'langchain/vectorstores/qdrant'; | ||
import type { Schemas as QdrantSchemas } from '@qdrant/js-client-rest'; | ||
import { createVectorStoreNode } from '../shared/createVectorStoreNode'; | ||
import { qdrantCollectionRLC } from '../shared/descriptions'; | ||
import { qdrantCollectionsSearch } from '../shared/methods/listSearch'; | ||
|
||
const sharedFields: INodeProperties[] = [qdrantCollectionRLC]; | ||
|
||
const insertFields: INodeProperties[] = [ | ||
{ | ||
displayName: 'Options', | ||
name: 'options', | ||
type: 'collection', | ||
placeholder: 'Add Option', | ||
default: {}, | ||
options: [ | ||
{ | ||
displayName: 'Collection Config', | ||
name: 'collectionConfig', | ||
type: 'json', | ||
default: '', | ||
description: | ||
'JSON options for creating a collection. <a href="https://qdrant.tech/documentation/concepts/collections">Learn more</a>.', | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
export const VectorStoreQdrant = createVectorStoreNode({ | ||
meta: { | ||
displayName: 'Qdrant Vector Store', | ||
name: 'vectorStoreQdrant', | ||
description: 'Work with your data in a Qdrant collection', | ||
icon: 'file:qdrant.svg', | ||
docsUrl: | ||
'https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.vectorstoreqdrant/', | ||
credentials: [ | ||
{ | ||
name: 'qdrantApi', | ||
required: true, | ||
}, | ||
], | ||
}, | ||
methods: { listSearch: { qdrantCollectionsSearch } }, | ||
insertFields, | ||
sharedFields, | ||
async getVectorStoreClient(context, filter, embeddings, itemIndex) { | ||
const collection = context.getNodeParameter('qdrantCollection', itemIndex, '', { | ||
extractValue: true, | ||
}) as string; | ||
|
||
const credentials = await context.getCredentials('qdrantApi'); | ||
|
||
const config: QdrantLibArgs = { | ||
url: credentials.qdrantUrl as string, | ||
apiKey: credentials.apiKey as string, | ||
collectionName: collection, | ||
}; | ||
|
||
return QdrantVectorStore.fromExistingCollection(embeddings, config); | ||
}, | ||
async populateVectorStore(context, embeddings, documents, itemIndex) { | ||
const collectionName = context.getNodeParameter('qdrantCollection', itemIndex, '', { | ||
extractValue: true, | ||
}) as string; | ||
|
||
// If collection config is not provided, the collection will be created with default settings | ||
// i.e. with the size of the passed embeddings and "Cosine" distance metric | ||
const { collectionConfig } = context.getNodeParameter('options', itemIndex, {}) as { | ||
collectionConfig?: QdrantSchemas['CreateCollection']; | ||
}; | ||
const credentials = await context.getCredentials('qdrantApi'); | ||
|
||
const config: QdrantLibArgs = { | ||
url: credentials.qdrantUrl as string, | ||
apiKey: credentials.apiKey as string, | ||
collectionName, | ||
collectionConfig, | ||
}; | ||
|
||
await QdrantVectorStore.fromDocuments(documents, embeddings, config); | ||
}, | ||
}); |
21 changes: 21 additions & 0 deletions
21
packages/@n8n/nodes-langchain/nodes/vector_store/VectorStoreQdrant/qdrant.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.