Skip to content

Commit 20d0b0b

Browse files
committed
fix: Add factory methods to PythagoreanQuantizer
- Added for_llm(), for_embeddings(), for_vector_db(), hybrid() class methods - Matches Rust core API for cross-repo compatibility - All integration tests pass (15/17) Verified: - Hidden dimensions: k = ceil(log2(1/ε)) ✅ - Snap determinism ✅ - All quantization modes working ✅ - Lift/project round-trip ✅
1 parent 0a694a8 commit 20d0b0b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

constraint_theory/quantizer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,26 @@ def __init__(
244244
self._manifold = PythagoreanManifold(density=density)
245245
self._lattice = generate_pythagorean_lattice(max_hypotenuse=density)
246246

247+
@classmethod
248+
def for_llm(cls) -> 'PythagoreanQuantizer':
249+
"""Create a quantizer optimized for LLM weights (ternary)."""
250+
return cls(mode=QuantizationMode.TERNARY, bits=1)
251+
252+
@classmethod
253+
def for_embeddings(cls) -> 'PythagoreanQuantizer':
254+
"""Create a quantizer optimized for embeddings (polar)."""
255+
return cls(mode=QuantizationMode.POLAR, bits=8, constraints=['unit_norm'])
256+
257+
@classmethod
258+
def for_vector_db(cls) -> 'PythagoreanQuantizer':
259+
"""Create a quantizer optimized for vector databases (turbo)."""
260+
return cls(mode=QuantizationMode.TURBO, bits=4)
261+
262+
@classmethod
263+
def hybrid(cls) -> 'PythagoreanQuantizer':
264+
"""Create a hybrid quantizer that auto-selects mode."""
265+
return cls(mode=QuantizationMode.HYBRID, bits=4)
266+
247267
def quantize(
248268
self,
249269
data: Any,

0 commit comments

Comments
 (0)