@@ -31,6 +31,26 @@ class FileIndex(BaseIndex):
31
31
32
32
def __init__ (self , app , id : int , name : str , config : dict ):
33
33
super ().__init__ (app , id , name , config )
34
+
35
+ self ._indexing_pipeline_cls : Type [BaseFileIndexIndexing ]
36
+ self ._retriever_pipeline_cls : list [Type [BaseFileIndexRetriever ]]
37
+ self ._selector_ui_cls : Type
38
+ self ._selector_ui : Any = None
39
+ self ._index_ui_cls : Type
40
+ self ._index_ui : Any = None
41
+
42
+ self ._default_settings : dict [str , dict ] = {}
43
+ self ._setting_mappings : dict [str , dict ] = {}
44
+
45
+ def _setup_resources (self ):
46
+ """Setup resources for the file index
47
+
48
+ The resources include:
49
+ - Database table
50
+ - Vector store
51
+ - Document store
52
+ - File storage path
53
+ """
34
54
Base = declarative_base ()
35
55
Source = type (
36
56
"Source" ,
@@ -50,6 +70,7 @@ def __init__(self, app, id: int, name: str, config: dict):
50
70
"date_created" : Column (
51
71
DateTime (timezone = True ), server_default = func .now ()
52
72
),
73
+ "user" : Column (Integer , default = 1 ),
53
74
},
54
75
)
55
76
Index = type (
@@ -61,6 +82,7 @@ def __init__(self, app, id: int, name: str, config: dict):
61
82
"source_id" : Column (String ),
62
83
"target_id" : Column (String ),
63
84
"relation_type" : Column (Integer ),
85
+ "user" : Column (Integer , default = 1 ),
64
86
},
65
87
)
66
88
self ._vs : BaseVectorStore = get_vectorstore (f"index_{ self .id } " )
@@ -74,16 +96,6 @@ def __init__(self, app, id: int, name: str, config: dict):
74
96
"FileStoragePath" : self ._fs_path ,
75
97
}
76
98
77
- self ._indexing_pipeline_cls : Type [BaseFileIndexIndexing ]
78
- self ._retriever_pipeline_cls : list [Type [BaseFileIndexRetriever ]]
79
- self ._selector_ui_cls : Type
80
- self ._selector_ui : Any = None
81
- self ._index_ui_cls : Type
82
- self ._index_ui : Any = None
83
-
84
- self ._default_settings : dict [str , dict ] = {}
85
- self ._setting_mappings : dict [str , dict ] = {}
86
-
87
99
def _setup_indexing_cls (self ):
88
100
"""Retrieve the indexing class for the file index
89
101
@@ -247,6 +259,7 @@ def on_create(self):
247
259
self .config = config
248
260
249
261
# create the resources
262
+ self ._setup_resources ()
250
263
self ._resources ["Source" ].metadata .create_all (engine ) # type: ignore
251
264
self ._resources ["Index" ].metadata .create_all (engine ) # type: ignore
252
265
self ._fs_path .mkdir (parents = True , exist_ok = True )
@@ -255,6 +268,7 @@ def on_delete(self):
255
268
"""Clean up the index when the user delete it"""
256
269
import shutil
257
270
271
+ self ._setup_resources ()
258
272
self ._resources ["Source" ].__table__ .drop (engine ) # type: ignore
259
273
self ._resources ["Index" ].__table__ .drop (engine ) # type: ignore
260
274
self ._vs .drop ()
@@ -263,6 +277,7 @@ def on_delete(self):
263
277
264
278
def on_start (self ):
265
279
"""Setup the classes and hooks"""
280
+ self ._setup_resources ()
266
281
self ._setup_indexing_cls ()
267
282
self ._setup_retriever_cls ()
268
283
self ._setup_file_index_ui_cls ()
@@ -326,9 +341,16 @@ def get_admin_settings(cls):
326
341
"Set 0 to disable."
327
342
),
328
343
},
344
+ "private" : {
345
+ "name" : "Make private" ,
346
+ "value" : False ,
347
+ "component" : "radio" ,
348
+ "choices" : [("Yes" , True ), ("No" , False )],
349
+ "info" : "If private, files will not be accessible across users." ,
350
+ },
329
351
}
330
352
331
- def get_indexing_pipeline (self , settings ) -> BaseFileIndexIndexing :
353
+ def get_indexing_pipeline (self , settings , user_id ) -> BaseFileIndexIndexing :
332
354
"""Define the interface of the indexing pipeline"""
333
355
334
356
prefix = f"index.options.{ self .id } ."
@@ -341,6 +363,7 @@ def get_indexing_pipeline(self, settings) -> BaseFileIndexIndexing:
341
363
342
364
obj = self ._indexing_pipeline_cls .get_pipeline (stripped_settings , self .config )
343
365
obj .set_resources (resources = self ._resources )
366
+ obj ._user_id = user_id
344
367
345
368
return obj
346
369
0 commit comments