The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
langchain-qdrant[patch]: Add ruff bandit rules to linter (#31815)
Mason Daugherty86a698d1b62c
diff --git a/libs/partners/qdrant/langchain_qdrant/qdrant.py b/libs/partners/qdrant/langchain_qdrant/qdrant.pyindex 80f3bf57a4..b5cfb7075e 100644--- a/libs/partners/qdrant/langchain_qdrant/qdrant.py+++ b/libs/partners/qdrant/langchain_qdrant/qdrant.py@@ -191,14 +191,14 @@ class QdrantVectorStore(VectorStore):"""Initialize a new instance of `QdrantVectorStore`.Example:- .. code-block:: python- qdrant = Qdrant(- client=client,- collection_name="my-collection",- embedding=OpenAIEmbeddings(),- retrieval_mode=RetrievalMode.HYBRID,- sparse_embedding=FastEmbedSparse(),- )+ .. code-block:: python+ qdrant = Qdrant(+ client=client,+ collection_name="my-collection",+ embedding=OpenAIEmbeddings(),+ retrieval_mode=RetrievalMode.HYBRID,+ sparse_embedding=FastEmbedSparse(),+ )"""if validate_embeddings:self._validate_embeddings(retrieval_mode, embedding, sparse_embedding)@@ -230,7 +230,7 @@ class QdrantVectorStore(VectorStore):"""Get the Qdrant client instance that is being used.Returns:- QdrantClient: An instance of `QdrantClient`.+ QdrantClient: An instance of ``QdrantClient``."""return self._client@@ -239,10 +239,10 @@ class QdrantVectorStore(VectorStore):"""Get the dense embeddings instance that is being used.Raises:- ValueError: If embeddings are `None`.+ ValueError: If embeddings are ``None``.Returns:- Embeddings: An instance of `Embeddings`.+ Embeddings: An instance of ``Embeddings``."""if self._embeddings is None:raise ValueError(@@ -255,10 +255,10 @@ class QdrantVectorStore(VectorStore):"""Get the sparse embeddings instance that is being used.Raises:- ValueError: If sparse embeddings are `None`.+ ValueError: If sparse embeddings are ``None``.Returns:- SparseEmbeddings: An instance of `SparseEmbeddings`.+ SparseEmbeddings: An instance of ``SparseEmbeddings``."""if self._sparse_embeddings is None:raise ValueError(@@ -302,7 +302,7 @@ class QdrantVectorStore(VectorStore):validate_collection_config: bool = True,**kwargs: Any,) -> QdrantVectorStore:- """Construct an instance of `QdrantVectorStore` from a list of texts.+ """Construct an instance of ``QdrantVectorStore`` from a list of texts.This is a user-friendly interface that:1. Creates embeddings, one for each text@@ -382,11 +382,11 @@ class QdrantVectorStore(VectorStore):validate_collection_config: bool = True,**kwargs: Any,) -> QdrantVectorStore:- """Construct an instance of `QdrantVectorStore` from an existing collection+ """Construct an instance of ``QdrantVectorStore`` from an existing collectionwithout adding any data.Returns:- QdrantVectorStore: A new instance of `QdrantVectorStore`.+ QdrantVectorStore: A new instance of ``QdrantVectorStore``."""client = QdrantClient(location=location,@@ -660,7 +660,6 @@ class QdrantVectorStore(VectorStore):Maximal marginal relevance optimizes for similarity to query AND diversityamong selected documents.-Returns:List of Documents selected by maximal marginal relevance."""@@ -911,16 +910,16 @@ class QdrantVectorStore(VectorStore):@staticmethoddef _cosine_relevance_score_fn(distance: float) -> float:- """Normalize the distance to a score on a scale [0, 1]."""+ """Normalize the distance to a score on a scale ``[0, 1]``."""return (distance + 1.0) / 2.0def _select_relevance_score_fn(self) -> Callable[[float], float]:"""- The 'correct' relevance function- may differ depending on a few things, including:- - the distance / similarity metric used by the VectorStore- - the scale of your embeddings (OpenAI's are unit normed. Many others are not!)- - embedding dimensionality+ The "correct" relevance function may differ depending on a few things,+ including:+ - The distance / similarity metric used by the VectorStore+ - The scale of your embeddings (OpenAI's are unit normed. Many others are not!)+ - Embedding dimensionality- etc."""@@ -1039,9 +1038,10 @@ class QdrantVectorStore(VectorStore):dense_embeddings = self.embeddings.embed_documents(list(texts))sparse_embeddings = self.sparse_embeddings.embed_documents(list(texts))- assert len(dense_embeddings) == len(- sparse_embeddings- ), "Mismatched length between dense and sparse embeddings."+ if len(dense_embeddings) != len(sparse_embeddings):+ raise ValueError(+ "Mismatched length between dense and sparse embeddings."+ )return [{@@ -1128,7 +1128,8 @@ class QdrantVectorStore(VectorStore):"set `force_recreate` to `True`.")- assert vector_config is not None, "VectorParams is None"+ if vector_config is None:+ raise ValueError("VectorParams is None")if isinstance(dense_embeddings, Embeddings):vector_size = len(dense_embeddings.embed_documents(["dummy_text"])[0])diff --git a/libs/partners/qdrant/langchain_qdrant/vectorstores.py b/libs/partners/qdrant/langchain_qdrant/vectorstores.pyindex 001d9a45cc..a7a4d43764 100644--- a/libs/partners/qdrant/langchain_qdrant/vectorstores.py+++ b/libs/partners/qdrant/langchain_qdrant/vectorstores.py@@ -105,7 +105,7 @@ class Qdrant(VectorStore):if embeddings is None and embedding_function is None:raise ValueError(- "`embeddings` value can't be None. Pass `Embeddings` instance."+ "`embeddings` value can't be None. Pass `embeddings` instance.")if embeddings is not None and embedding_function is not None:@@ -161,7 +161,7 @@ class Qdrant(VectorStore):uuid-like strings.batch_size:How many vectors upload per-request.- Default: 64+ Default: ``64``Returns:List of ids from adding the texts into the vectorstore.@@ -196,7 +196,7 @@ class Qdrant(VectorStore):uuid-like strings.batch_size:How many vectors upload per-request.- Default: 64+ Default: ``64``Returns:List of ids from adding the texts into the vectorstore.@@ -1669,10 +1669,11 @@ class Qdrant(VectorStore):f"`None`. If you want to recreate the collection, set "f"`force_recreate` parameter to `True`.")- assert isinstance(current_vector_config, models.VectorParams), (- "Expected current_vector_config to be an instance of "- f"models.VectorParams, but got {type(current_vector_config)}"- )+ if not isinstance(current_vector_config, models.VectorParams):+ raise ValueError(+ "Expected current_vector_config to be an instance of "+ f"models.VectorParams, but got {type(current_vector_config)}"+ )# Check if the vector configuration has the same dimensionality.if current_vector_config.size != vector_size:raise QdrantException(@@ -1829,11 +1830,11 @@ class Qdrant(VectorStore):f"`None`. If you want to recreate the collection, set "f"`force_recreate` parameter to `True`.")-- assert isinstance(current_vector_config, models.VectorParams), (- "Expected current_vector_config to be an instance of "- f"models.VectorParams, but got {type(current_vector_config)}"- )+ if not isinstance(current_vector_config, models.VectorParams):+ raise ValueError(+ "Expected current_vector_config to be an instance of "+ f"models.VectorParams, but got {type(current_vector_config)}"+ )# Check if the vector configuration has the same dimensionality.if current_vector_config.size != vector_size:diff --git a/libs/partners/qdrant/pyproject.toml b/libs/partners/qdrant/pyproject.tomlindex 94eee7bdfd..14dca0ccd2 100644--- a/libs/partners/qdrant/pyproject.toml+++ b/libs/partners/qdrant/pyproject.toml@@ -51,7 +51,7 @@ langchain-core = { path = "../../core", editable = true }target-version = "py39"[tool.ruff.lint]-select = ["E", "F", "I", "T201", "UP"]+select = ["E", "F", "I", "T201", "UP", "S"]ignore = [ "UP007", ][tool.mypy]@@ -67,3 +67,9 @@ markers = ["compile: mark placeholder test used to compile integration tests without running them",]asyncio_mode = "auto"++[tool.ruff.lint.extend-per-file-ignores]+"tests/**/*.py" = [+ "S101", # Tests need assertions+ "S311", # Standard pseudo-random generators are not suitable for cryptographic purposes+]