diff --git a/nodes/test/mocks/chromadb/__init__.py b/nodes/test/mocks/chromadb/__init__.py index 94a09983c..0987cd948 100644 --- a/nodes/test/mocks/chromadb/__init__.py +++ b/nodes/test/mocks/chromadb/__init__.py @@ -187,7 +187,11 @@ def get( if count < offset: count += 1 continue - + + # Apply limit (must be checked before append so limit=0 returns zero items) + if limit is not None and len(results["ids"]) >= limit: + break + results["ids"].append(id) if "metadatas" in include: results["metadatas"].append(self._serialize_metadata(metadata)) @@ -197,11 +201,7 @@ def get( results["embeddings"].append(data.get("embedding")) count += 1 - - # Apply limit - if limit and len(results["ids"]) >= limit: - break - + return results def upsert( diff --git a/nodes/test/mocks/psycopg2/__init__.py b/nodes/test/mocks/psycopg2/__init__.py index 541e815fc..bb77fdb10 100644 --- a/nodes/test/mocks/psycopg2/__init__.py +++ b/nodes/test/mocks/psycopg2/__init__.py @@ -181,7 +181,7 @@ def _handle_semantic_search(self, query: str, params: Tuple): query_vector = p.tolist() elif isinstance(p, (list, tuple)) and len(p) > 3: query_vector = list(p) - elif isinstance(p, int) and p < 1000: + elif isinstance(p, int) and not isinstance(p, bool) and p < 1000: limit = p else: filter_params.append(p) @@ -305,7 +305,7 @@ def _extract_limit(self, query: str, params: Tuple) -> Optional[int]: if "limit" in query.lower() and params: # Last param is often the limit for p in reversed(params): - if isinstance(p, int) and p < 10000: + if isinstance(p, int) and not isinstance(p, bool) and p < 10000: return p return None diff --git a/nodes/test/mocks/weaviate/__init__.py b/nodes/test/mocks/weaviate/__init__.py index 82c0f18d8..c9543cdf1 100644 --- a/nodes/test/mocks/weaviate/__init__.py +++ b/nodes/test/mocks/weaviate/__init__.py @@ -275,7 +275,7 @@ def near_vector( )) # Sort by distance (lower is better for cosine distance) - results.sort(key=lambda x: x.metadata.distance if x.metadata.distance else 1.0) + results.sort(key=lambda x: x.metadata.distance if x.metadata.distance is not None else 1.0) return QueryResult(objects=results[:limit])