Skip to content

Commit

Permalink
improve error handling and function comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ttmenezes committed Nov 18, 2024
1 parent 5ac7cbe commit 422d76b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def __init__(
processing semantic queries.
For more information on parameters, see the
[official Azure AI Search documentation](https://learn.microsoft.com/en-us/azure/search/).
:raises TypeError: If the document store is not an instance of AzureAISearchDocumentStore.
:raises RuntimeError: If the query is not valid, or if the document store is not correctly configured.
"""
self._filters = filters or {}
Expand All @@ -56,7 +57,7 @@ def __init__(
self._kwargs = kwargs
if not isinstance(document_store, AzureAISearchDocumentStore):
message = "document_store must be an instance of AzureAISearchDocumentStore"
raise Exception(message)
raise TypeError(message)

def to_dict(self) -> Dict[str, Any]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(
Filters are applied during the hybrid search to ensure the Retriever returns
`top_k` matching documents.
:param top_k: Maximum number of documents to return.
:filter_policy: Policy to determine how filters are applied.
:param filter_policy: Policy to determine how filters are applied.
:param kwargs: Additional keyword arguments to pass to the Azure AI's search endpoint.
Some of the supported parameters:
- `query_type`: A string indicating the type of query to perform. Possible values are
Expand All @@ -44,8 +44,9 @@ def __init__(
processing semantic queries.
For more information on parameters, see the
[official Azure AI Search documentation](https://learn.microsoft.com/en-us/azure/search/).
:raises TypeError: If the document store is not an instance of AzureAISearchDocumentStore.
:raises RuntimeError: If query or query_embedding are invalid, or if document store is not correctly configured.
"""
self._filters = filters or {}
self._top_k = top_k
Expand All @@ -57,7 +58,7 @@ def __init__(

if not isinstance(document_store, AzureAISearchDocumentStore):
message = "document_store must be an instance of AzureAISearchDocumentStore"
raise Exception(message)
raise TypeError(message)

def to_dict(self) -> Dict[str, Any]:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,17 @@ def write_documents(self, documents: List[Document], policy: DuplicatePolicy = D
Writes the provided documents to search index.
:param documents: documents to write to the index.
:param policy: Policy to determine how duplicates are handled.
:raises ValueError: If the documents are not of type Document.
:raises TypeError: If the document ids are not strings.
:return: the number of documents added to index.
"""

def _convert_input_document(documents: Document):
document_dict = asdict(documents)
if not isinstance(document_dict["id"], str):
msg = f"Document id {document_dict['id']} is not a string, "
raise Exception(msg)
raise TypeError(msg)
index_document = self._convert_haystack_documents_to_azure(document_dict)

return index_document
Expand Down

0 comments on commit 422d76b

Please sign in to comment.