Skip to content

Commit

Permalink
fix: bug when deleting sources
Browse files Browse the repository at this point in the history
  • Loading branch information
zaldivards committed Aug 23, 2024
1 parent c6bdb7a commit af069e6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 5 additions & 2 deletions api/contextqa/services/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,20 @@ def remove_sources(session: Session, sources: list[str], client: StoreClient) ->
Specific store client
"""
store_settings = get_or_set(kind="store")
db_index = store_settings.store_params.get("collection", "index")
complete_index_name = (
f"{store_settings.store_params['home']}/{db_index}" if store_settings.store == "chroma" else db_index
)
sources_to_remove = (
session.query(Source.id)
.join(Index)
.join(VectorStore)
.filter(
Source.name.in_(sources),
Index.name == store_settings.store_params.get("collection", "index"),
Index.name == complete_index_name,
VectorStore.name == store_settings.store,
)
)

removed_sources = session.query(Source).filter(Source.id.in_(sources_to_remove)).delete(synchronize_session=False)

chunks_to_remove = client.get_ids(sources)
Expand Down
3 changes: 2 additions & 1 deletion api/contextqa/utils/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def get_ids(self, sources: list[str]) -> list[str]:
chunks_to_remove = []
for source in sources:
if source.endswith(".pdf"):
source = f"{get_or_set('extra').media_dir}/{source}"
# pdf sources have the template prefix: {}
source = f"{{}}/{source}"
chunks = self.get(source)
chunks_to_remove.extend(chunks)

Expand Down

0 comments on commit af069e6

Please sign in to comment.