Skip to content

Commit

Permalink
Remove redundant attributes in the file index
Browse files Browse the repository at this point in the history
  • Loading branch information
trducng committed Apr 19, 2024
1 parent c6045bc commit 587122e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
1 change: 0 additions & 1 deletion libs/ktem/ktem/index/file/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def __init__(self, app, id: int, name: str, config: dict):
"relation_type": Column(Integer),
},
)
self._db_tables: dict[str, Any] = {"Source": Source, "Index": Index}
self._vs: BaseVectorStore = get_vectorstore(f"index_{self.id}")
self._docstore: BaseDocumentStore = get_docstore(f"index_{self.id}")
self._fs_path = filestorage_path / f"index_{self.id}"
Expand Down
14 changes: 7 additions & 7 deletions libs/ktem/ktem/index/file/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ def to_confirm_delete(self, file_id):
def delete_yes_event(self, file_id):
with Session(engine) as session:
source = session.execute(
select(self._index._db_tables["Source"]).where(
self._index._db_tables["Source"].id == file_id
select(self._index._resources["Source"]).where(
self._index._resources["Source"].id == file_id
)
).first()
if source:
session.delete(source[0])

vs_ids, ds_ids = [], []
index = session.execute(
select(self._index._db_tables["Index"]).where(
self._index._db_tables["Index"].source_id == file_id
select(self._index._resources["Index"]).where(
self._index._resources["Index"].source_id == file_id
)
).all()
for each in index:
Expand Down Expand Up @@ -431,7 +431,7 @@ def index_files_from_dir(self, folder_path, reindex, settings):
return self.index_fn(files, reindex, settings)

def list_file(self):
Source = self._index._db_tables["Source"]
Source = self._index._resources["Source"]
with Session(engine) as session:
statement = select(Source)
results = [
Expand Down Expand Up @@ -494,7 +494,7 @@ def validate(self, files: list[str]):
if max_number_of_files := self._index.config.get("max_number_of_files", 0):
with Session(engine) as session:
current_num_files = session.query(
self._index._db_tables["Source"].id
self._index._resources["Source"].id
).count()
if len(paths) + current_num_files > max_number_of_files:
errors.append(
Expand Down Expand Up @@ -566,7 +566,7 @@ def load_files(self, selected_files):
options = []
available_ids = []
with Session(engine) as session:
statement = select(self._index._db_tables["Source"])
statement = select(self._index._resources["Source"])
results = session.execute(statement).all()
for result in results:
available_ids.append(result[0].id)
Expand Down

0 comments on commit 587122e

Please sign in to comment.