diff --git a/libs/astradb/langchain_astradb/__init__.py b/libs/astradb/langchain_astradb/__init__.py index 588e2b0..37ddcf6 100644 --- a/libs/astradb/langchain_astradb/__init__.py +++ b/libs/astradb/langchain_astradb/__init__.py @@ -1,17 +1,14 @@ """Astra DB integration for LangChain.""" -# ruff: noqa: I001 - from astrapy.info import CollectionVectorServiceOptions from langchain_astradb.cache import AstraDBCache, AstraDBSemanticCache from langchain_astradb.chat_message_histories import AstraDBChatMessageHistory from langchain_astradb.document_loaders import AstraDBLoader +from langchain_astradb.graph_vectorstores import AstraDBGraphVectorStore from langchain_astradb.storage import AstraDBByteStore, AstraDBStore from langchain_astradb.vectorstores import AstraDBVectorStore -from langchain_astradb.graph_vectorstores import AstraDBGraphVectorStore - __all__ = [ "AstraDBByteStore", "AstraDBStore", diff --git a/libs/astradb/langchain_astradb/graph_vectorstores.py b/libs/astradb/langchain_astradb/graph_vectorstores.py index aa5b2fd..a90fb6b 100644 --- a/libs/astradb/langchain_astradb/graph_vectorstores.py +++ b/libs/astradb/langchain_astradb/graph_vectorstores.py @@ -1,8 +1,5 @@ """Astra DB graph vector store integration.""" -# Leave TODO's alone -# ruff: noqa: FIX002 TD002 TD003 - from __future__ import annotations import secrets @@ -21,8 +18,8 @@ from langchain_core.documents import Document from typing_extensions import override -from langchain_astradb import AstraDBVectorStore from langchain_astradb.utils.mmr_traversal import MmrHelper +from langchain_astradb.vectorstores import AstraDBVectorStore if TYPE_CHECKING: from langchain_core.embeddings import Embeddings diff --git a/libs/astradb/langchain_astradb/utils/mmr_traversal.py b/libs/astradb/langchain_astradb/utils/mmr_traversal.py index 04b3dea..e2cf5ab 100644 --- a/libs/astradb/langchain_astradb/utils/mmr_traversal.py +++ b/libs/astradb/langchain_astradb/utils/mmr_traversal.py @@ -1,7 +1,5 @@ """Tools for the Graph Traversal Maximal Marginal Relevance (MMR) reranking.""" -# ruff: noqa: EM101 TRY003 - from __future__ import annotations import dataclasses @@ -141,10 +139,11 @@ def _pop_candidate(self, candidate_id: str) -> NDArray[np.float32]: # Get the embedding for the id. index = self.candidate_id_to_index.pop(candidate_id) if self.candidates[index].id != candidate_id: - raise ValueError( + msg = ( "ID in self.candidate_id_to_index doesn't match the ID of the " "corresponding index in self.candidates" ) + raise ValueError(msg) embedding: NDArray[np.float32] = self.candidate_embeddings[index].copy() # Swap that index with the last index in the candidates and diff --git a/libs/astradb/langchain_astradb/vectorstores.py b/libs/astradb/langchain_astradb/vectorstores.py index c807742..4a2ee8f 100644 --- a/libs/astradb/langchain_astradb/vectorstores.py +++ b/libs/astradb/langchain_astradb/vectorstores.py @@ -983,10 +983,7 @@ def add_texts( inserted_ids = insert_many_result.inserted_ids except InsertManyException as err: # check that the error is solely due to already-existing documents - error_codes = { - getattr(err_desc, "error_code", None) - for err_desc in err.error_descriptors - } + error_codes = {err_desc.error_code for err_desc in err.error_descriptors} if error_codes == {DOCUMENT_ALREADY_EXISTS_API_ERROR_CODE}: inserted_ids = err.partial_result.inserted_ids inserted_ids_set = set(inserted_ids) @@ -1115,10 +1112,7 @@ async def aadd_texts( inserted_ids = insert_many_result.inserted_ids except InsertManyException as err: # check that the error is solely due to already-existing documents - error_codes = { - getattr(err_desc, "error_code", None) - for err_desc in err.error_descriptors - } + error_codes = {err_desc.error_code for err_desc in err.error_descriptors} if error_codes == {DOCUMENT_ALREADY_EXISTS_API_ERROR_CODE}: inserted_ids = err.partial_result.inserted_ids inserted_ids_set = set(inserted_ids) diff --git a/libs/astradb/pyproject.toml b/libs/astradb/pyproject.toml index 464ded7..563e900 100644 --- a/libs/astradb/pyproject.toml +++ b/libs/astradb/pyproject.toml @@ -69,10 +69,13 @@ flake8-annotations.mypy-init-return = true select = ["ALL"] ignore = [ "COM812", # Messes with the formatter - "ERA", # Do we want to activate (no commented code) ? + "D101", # We prefer using the __init__ docstring to document the class + "ERA001", # Do we want to activate (no commented code) ? + "FIX002", # Accept TODOs "ISC001", # Messes with the formatter "PLR09", # TODO: do we enforce these ones (complexity) ? - "D101", # We prefer using the __init__ docstring to document the class + "TD002", # We have TODOs authors by git + "TD003", ] [tool.ruff.lint.per-file-ignores] diff --git a/libs/astradb/tests/integration_tests/test_graphvectorstore.py b/libs/astradb/tests/integration_tests/test_graphvectorstore.py index 8e32031..dfa0a17 100644 --- a/libs/astradb/tests/integration_tests/test_graphvectorstore.py +++ b/libs/astradb/tests/integration_tests/test_graphvectorstore.py @@ -3,8 +3,6 @@ Refer to `test_vectorstores.py` for the requirements to run. """ -# ruff: noqa: FIX002 TD002 TD003 - from __future__ import annotations from typing import TYPE_CHECKING