Skip to content

Commit 4e23442

Browse files
fix: add explicit boolean check in FallbackHashEmbeddings constructor
- Add isinstance(dimension, bool) check that raises TypeError - Prevents boolean values from being accepted as dimensions - Maintains existing ValueError for other non-int types - Improves type safety and error message clarity This addresses the issue where bool is a subclass of int in Python, which could lead to unexpected behavior when boolean values are passed as dimension parameters.
1 parent 5a2d3b2 commit 4e23442

File tree

1 file changed

+2
-0
lines changed
  • src/contextforge_memory/embeddings

1 file changed

+2
-0
lines changed

src/contextforge_memory/embeddings/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def __init__(self, dimension: int = 32) -> None:
104104
dimension: The dimension of hash-based embeddings (default: 32).
105105
Must be an integer between 2 and 32 (inclusive).
106106
"""
107+
if isinstance(dimension, bool):
108+
raise TypeError("dimension must be an integer, not a boolean")
107109
if not isinstance(dimension, int):
108110
raise ValueError("dimension must be an integer")
109111
if dimension < 2:

0 commit comments

Comments
 (0)