@@ -289,7 +289,7 @@ const getDocumentStoreFileChunks = async (
289
289
}
290
290
291
291
// Sync and refresh chunks for a specific loader or store
292
- const syncAndRefreshChunks = async ( storeId : string , fileId : string , userId ? : string , organizationId ? : string ) => {
292
+ const syncAndRefreshChunks = async ( storeId : string , fileId : string , userId : string , organizationId : string ) => {
293
293
try {
294
294
const appServer = getRunningExpressApp ( )
295
295
const componentNodes = appServer . nodesPool . componentNodes
@@ -460,7 +460,7 @@ const deleteDocumentStoreFileChunk = async (storeId: string, docId: string, chun
460
460
}
461
461
}
462
462
463
- const deleteVectorStoreFromStore = async ( storeId : string ) => {
463
+ const deleteVectorStoreFromStore = async ( storeId : string , userId : string , organizationId : string ) => {
464
464
try {
465
465
const appServer = getRunningExpressApp ( )
466
466
const componentNodes = appServer . nodesPool . componentNodes
@@ -588,7 +588,12 @@ const editDocumentStoreFileChunk = async (
588
588
}
589
589
}
590
590
591
- const updateDocumentStore = async ( documentStore : DocumentStore , updatedDocumentStore : DocumentStore ) => {
591
+ const updateDocumentStore = async (
592
+ documentStore : DocumentStore ,
593
+ updatedDocumentStore : DocumentStore ,
594
+ userId : string ,
595
+ organizationId : string
596
+ ) => {
592
597
try {
593
598
const appServer = getRunningExpressApp ( )
594
599
const tmpUpdatedDocumentStore = appServer . AppDataSource . getRepository ( DocumentStore ) . merge ( documentStore , updatedDocumentStore )
@@ -602,7 +607,7 @@ const updateDocumentStore = async (documentStore: DocumentStore, updatedDocument
602
607
}
603
608
}
604
609
605
- const _saveFileToStorage = async ( fileBase64 : string , entity : DocumentStore ) => {
610
+ const _saveFileToStorage = async ( fileBase64 : string , entity : DocumentStore , userId : string , organizationId : string ) => {
606
611
const splitDataURI = fileBase64 . split ( ',' )
607
612
const filename = splitDataURI . pop ( ) ?. split ( ':' ) [ 1 ] ?? ''
608
613
const bf = Buffer . from ( splitDataURI . pop ( ) || '' , 'base64' )
@@ -980,15 +985,15 @@ const _saveChunksToStorage = async (
980
985
for ( let j = 0 ; j < files . length ; j ++ ) {
981
986
const file = files [ j ]
982
987
if ( re . test ( file ) ) {
983
- const fileMetadata = await _saveFileToStorage ( file , entity )
988
+ const fileMetadata = await _saveFileToStorage ( file , entity , data . userId , data . organizationId )
984
989
fileNames . push ( fileMetadata . name )
985
990
filesWithMetadata . push ( fileMetadata )
986
991
}
987
992
}
988
993
if ( fileNames . length ) data . loaderConfig [ keys [ i ] ] = 'FILE-STORAGE::' + JSON . stringify ( fileNames )
989
994
} else if ( re . test ( input ) ) {
990
995
const fileNames : string [ ] = [ ]
991
- const fileMetadata = await _saveFileToStorage ( input , entity )
996
+ const fileMetadata = await _saveFileToStorage ( input , entity , data . userId , data . organizationId )
992
997
fileNames . push ( fileMetadata . name )
993
998
filesWithMetadata . push ( fileMetadata )
994
999
data . loaderConfig [ keys [ i ] ] = 'FILE-STORAGE::' + JSON . stringify ( fileNames )
@@ -1024,7 +1029,9 @@ const _saveChunksToStorage = async (
1024
1029
id : uuidv4 ( ) ,
1025
1030
chunkNo : index + 1 ,
1026
1031
pageContent : chunk . pageContent ,
1027
- metadata : JSON . stringify ( chunk . metadata )
1032
+ metadata : JSON . stringify ( chunk . metadata ) ,
1033
+ userId : data . userId ,
1034
+ organizationId : data . organizationId
1028
1035
}
1029
1036
const dChunk = appDataSource . getRepository ( DocumentStoreFileChunk ) . create ( docChunk )
1030
1037
await appDataSource . getRepository ( DocumentStoreFileChunk ) . save ( dChunk )
@@ -1139,7 +1146,13 @@ const updateVectorStoreConfigOnly = async (data: ICommonObject) => {
1139
1146
)
1140
1147
}
1141
1148
}
1142
- const saveVectorStoreConfig = async ( appDataSource : DataSource , data : ICommonObject , isStrictSave = true ) => {
1149
+ const saveVectorStoreConfig = async (
1150
+ appDataSource : DataSource ,
1151
+ data : ICommonObject ,
1152
+ isStrictSave = true ,
1153
+ userId : string ,
1154
+ organizationId : string
1155
+ ) => {
1143
1156
try {
1144
1157
const entity = await appDataSource . getRepository ( DocumentStore ) . findOneBy ( {
1145
1158
id : data . storeId
@@ -1207,14 +1220,24 @@ export const insertIntoVectorStore = async ({
1207
1220
componentNodes,
1208
1221
telemetry,
1209
1222
data,
1210
- isStrictSave
1223
+ isStrictSave,
1224
+ userId,
1225
+ organizationId
1211
1226
} : IExecuteVectorStoreInsert ) => {
1212
1227
try {
1213
- const entity = await saveVectorStoreConfig ( appDataSource , data , isStrictSave )
1228
+ const entity = await saveVectorStoreConfig ( appDataSource , data , isStrictSave , userId , organizationId )
1214
1229
entity . status = DocumentStoreStatus . UPSERTING
1215
1230
await appDataSource . getRepository ( DocumentStore ) . save ( entity )
1216
1231
1217
- const indexResult = await _insertIntoVectorStoreWorkerThread ( appDataSource , componentNodes , telemetry , data , isStrictSave )
1232
+ const indexResult = await _insertIntoVectorStoreWorkerThread (
1233
+ appDataSource ,
1234
+ componentNodes ,
1235
+ telemetry ,
1236
+ data ,
1237
+ isStrictSave ,
1238
+ userId ,
1239
+ organizationId
1240
+ )
1218
1241
return indexResult
1219
1242
} catch ( error ) {
1220
1243
throw new InternalFlowiseError (
@@ -1224,7 +1247,7 @@ export const insertIntoVectorStore = async ({
1224
1247
}
1225
1248
}
1226
1249
1227
- const insertIntoVectorStoreMiddleware = async ( data : ICommonObject , isStrictSave = true ) => {
1250
+ const insertIntoVectorStoreMiddleware = async ( data : ICommonObject , isStrictSave = true , userId : string , organizationId : string ) => {
1228
1251
try {
1229
1252
const appServer = getRunningExpressApp ( )
1230
1253
const appDataSource = appServer . AppDataSource
@@ -1238,8 +1261,8 @@ const insertIntoVectorStoreMiddleware = async (data: ICommonObject, isStrictSave
1238
1261
data,
1239
1262
isStrictSave,
1240
1263
isVectorStoreInsert : true ,
1241
- userId : data . userId ,
1242
- organizationId : data . organizationId
1264
+ userId,
1265
+ organizationId
1243
1266
}
1244
1267
1245
1268
if ( process . env . MODE === MODE . QUEUE ) {
@@ -1270,10 +1293,12 @@ const _insertIntoVectorStoreWorkerThread = async (
1270
1293
componentNodes : IComponentNodes ,
1271
1294
telemetry : Telemetry ,
1272
1295
data : ICommonObject ,
1273
- isStrictSave = true
1296
+ isStrictSave = true ,
1297
+ userId : string ,
1298
+ organizationId : string
1274
1299
) => {
1275
1300
try {
1276
- const entity = await saveVectorStoreConfig ( appDataSource , data , isStrictSave )
1301
+ const entity = await saveVectorStoreConfig ( appDataSource , data , isStrictSave , userId , organizationId )
1277
1302
let upsertHistory : Record < string , any > = { }
1278
1303
const chatflowid = data . storeId // fake chatflowid because this is not tied to any chatflow
1279
1304
@@ -1351,7 +1376,7 @@ const _insertIntoVectorStoreWorkerThread = async (
1351
1376
}
1352
1377
1353
1378
// Get all component nodes - Embeddings
1354
- const getEmbeddingProviders = async ( ) => {
1379
+ const getEmbeddingProviders = async ( userId : string , organizationId : string ) => {
1355
1380
try {
1356
1381
const dbResponse = await nodesService . getAllNodesForCategory ( 'Embeddings' )
1357
1382
return dbResponse . filter ( ( node ) => ! node . tags ?. includes ( 'LlamaIndex' ) )
@@ -1390,13 +1415,15 @@ const getRecordManagerProviders = async () => {
1390
1415
}
1391
1416
}
1392
1417
1393
- const queryVectorStore = async ( data : ICommonObject ) => {
1418
+ const queryVectorStore = async ( data : ICommonObject , userId : string , organizationId : string ) => {
1394
1419
try {
1395
1420
const appServer = getRunningExpressApp ( )
1396
1421
const componentNodes = appServer . nodesPool . componentNodes
1397
1422
1398
1423
const entity = await appServer . AppDataSource . getRepository ( DocumentStore ) . findOneBy ( {
1399
- id : data . storeId
1424
+ id : data . storeId ,
1425
+ userId,
1426
+ organizationId
1400
1427
} )
1401
1428
if ( ! entity ) {
1402
1429
throw new InternalFlowiseError ( StatusCodes . INTERNAL_SERVER_ERROR , `Document store ${ data . storeId } not found` )
@@ -1597,7 +1624,9 @@ const upsertDocStore = async (
1597
1624
storeId : string ,
1598
1625
data : IDocumentStoreUpsertData ,
1599
1626
files : Express . Multer . File [ ] = [ ] ,
1600
- isRefreshExisting = false
1627
+ isRefreshExisting = false ,
1628
+ userId : string ,
1629
+ organizationId : string
1601
1630
) => {
1602
1631
const docId = data . docId
1603
1632
let metadata = { }
@@ -1683,7 +1712,7 @@ const upsertDocStore = async (
1683
1712
const docStoreBody = typeof data . docStore === 'string' ? JSON . parse ( data . docStore ) : data . docStore
1684
1713
const newDocumentStore = docStoreBody ?? { name : `Document Store ${ Date . now ( ) . toString ( ) } ` }
1685
1714
const docStore = DocumentStoreDTO . toEntity ( newDocumentStore )
1686
- const documentStore = appDataSource . getRepository ( DocumentStore ) . create ( docStore )
1715
+ const documentStore = appDataSource . getRepository ( DocumentStore ) . create ( { ... docStore , userId , organizationId } )
1687
1716
const dbResponse = await appDataSource . getRepository ( DocumentStore ) . save ( documentStore )
1688
1717
storeId = dbResponse . id
1689
1718
}
@@ -1872,7 +1901,17 @@ export const executeDocStoreUpsert = async ({
1872
1901
} : IExecuteDocStoreUpsert ) => {
1873
1902
const results = [ ]
1874
1903
for ( const item of totalItems ) {
1875
- const res = await upsertDocStore ( appDataSource , componentNodes , telemetry , storeId , item , files , isRefreshAPI )
1904
+ const res = await upsertDocStore (
1905
+ appDataSource ,
1906
+ componentNodes ,
1907
+ telemetry ,
1908
+ storeId ,
1909
+ item ,
1910
+ files ,
1911
+ isRefreshAPI ,
1912
+ userId ,
1913
+ organizationId
1914
+ )
1876
1915
results . push ( res )
1877
1916
}
1878
1917
return isRefreshAPI ? results : results [ 0 ]
0 commit comments