Skip to content
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

fix error in log message #2719

Merged
merged 5 commits into from
Jun 24, 2022
Merged
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
9 changes: 6 additions & 3 deletions haystack/document_stores/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -607,11 +607,12 @@ def get_documents_by_id(
) -> List[Document]:
pass

def _drop_duplicate_documents(self, documents: List[Document]) -> List[Document]:
def _drop_duplicate_documents(self, documents: List[Document], index: Optional[str] = None) -> List[Document]:
"""
Drop duplicates documents based on same hash ID

:param documents: A list of Haystack Document objects.
:param index: name of the index
:return: A list of Haystack Document objects.
"""
_hash_ids: Set = set([])
Expand All @@ -620,7 +621,8 @@ def _drop_duplicate_documents(self, documents: List[Document]) -> List[Document]
for document in documents:
if document.id in _hash_ids:
logger.info(
f"Duplicate Documents: Document with id '{document.id}' already exists in index " f"'{self.index}'"
f"Duplicate Documents: Document with id '{document.id}' already exists in index "
f"'{index or self.index}'"
)
continue
_documents.append(document)
Expand All @@ -640,6 +642,7 @@ def _handle_duplicate_documents(
documents that are not in the index yet.

:param documents: A list of Haystack Document objects.
:param index: name of the index
:param duplicate_documents: Handle duplicates document based on parameter options.
Parameter options : ( 'skip','overwrite','fail')
skip (default option): Ignore the duplicates documents
Expand All @@ -652,7 +655,7 @@ def _handle_duplicate_documents(

index = index or self.index
if duplicate_documents in ("skip", "fail"):
documents = self._drop_duplicate_documents(documents)
documents = self._drop_duplicate_documents(documents, index)
documents_found = self.get_documents_by_id(ids=[doc.id for doc in documents], index=index, headers=headers)
ids_exist_in_db: List[str] = [doc.id for doc in documents_found]

Expand Down