Skip to content

fix: Use document store ID instead of name for referential integrity in agent flows #4874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions packages/components/nodes/agentflow/Agent/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,28 @@ class Agent_Agentflow implements INode {
const nodeInstanceFilePath = options.componentNodes['retrieverTool'].filePath as string
const nodeModule = await import(nodeInstanceFilePath)
const newRetrieverToolNodeInstance = new nodeModule.nodeClass()
const [storeId, storeName] = knowledgeBase.documentStore.split(':')

// Handle both old format (id:name) and new format (id only)
let storeId = knowledgeBase.documentStore
let storeName = ''

if (knowledgeBase.documentStore.includes(':')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we can just directly fetch the storeName from database:

const [storeId] = knowledgeBase.documentStore.split(':')
...
const storeName = store?.name || storeId

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me fix this issues!

// Old format - split to get ID and name
;[storeId, storeName] = knowledgeBase.documentStore.split(':')
} else {
// New format - only ID is stored, need to look up current name
storeId = knowledgeBase.documentStore
const appDataSource = options.appDataSource as DataSource
const databaseEntities = options.databaseEntities as IDatabaseEntity
const store = await appDataSource.getRepository(databaseEntities['DocumentStore']).findOneBy({ id: storeId })
storeName = store?.name || storeId // Fallback to ID if store not found
}

// Always fetch the current store name from database for referential integrity
const appDataSource = options.appDataSource as DataSource
const databaseEntities = options.databaseEntities as IDatabaseEntity
const store = await appDataSource.getRepository(databaseEntities['DocumentStore']).findOneBy({ id: storeId })
const currentStoreName = store?.name || storeId // Use current name from database

const docStoreVectorInstanceFilePath = options.componentNodes['documentStoreVS'].filePath as string
const docStoreVectorModule = await import(docStoreVectorInstanceFilePath)
Expand All @@ -571,7 +592,7 @@ class Agent_Agentflow implements INode {
...nodeData,
inputs: {
...nodeData.inputs,
name: storeName
name: currentStoreName
.toLowerCase()
.replace(/ /g, '_')
.replace(/[^a-z0-9_-]/g, ''),
Expand All @@ -591,7 +612,7 @@ class Agent_Agentflow implements INode {
const componentNode = options.componentNodes['retrieverTool']

availableTools.push({
name: storeName
name: currentStoreName
.toLowerCase()
.replace(/ /g, '_')
.replace(/[^a-z0-9_-]/g, ''),
Expand Down
2 changes: 1 addition & 1 deletion packages/components/nodes/agentflow/Retriever/Retriever.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Retriever_Agentflow implements INode {
const knowledgeBases = nodeData.inputs?.retrieverKnowledgeDocumentStores as IKnowledgeBase[]
if (knowledgeBases && knowledgeBases.length > 0) {
for (const knowledgeBase of knowledgeBases) {
const [storeId, _] = knowledgeBase.documentStore.split(':')
const [storeId] = knowledgeBase.documentStore.split(':')

const docStoreVectorInstanceFilePath = options.componentNodes['documentStoreVS'].filePath as string
const docStoreVectorModule = await import(docStoreVectorInstanceFilePath)
Expand Down