Skip to content

Commit 93cb809

Browse files
authored
Merge pull request #62 from krish1925/feat/binary-format-v2
feat: binary format v2 — CRC32, header padding, strict reader, zero-copy ready
2 parents 442cf06 + 45821f6 commit 93cb809

76 files changed

Lines changed: 7336 additions & 3965 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎isotrieve-npm/CHANGELOG.md‎

Lines changed: 27 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -5,141 +5,34 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [1.0.0] - 2026-02-04
8+
## [0.1.0] - 2026-07-28
99

1010
### Added
1111

12-
#### Core Package (@isotrieve/core)
13-
- Initial release of Isotrieve protocol implementation
14-
- `Isotrieve` class for agent communication
15-
- Linear transfer matrix computation using least squares
16-
- Quality monitoring and validation
17-
- Automatic recalibration detection
18-
- Default vocabulary (150+ curated terms)
19-
- Extended vocabulary generation (up to 10k+ items)
20-
- TypeScript type definitions
21-
- Comprehensive API documentation
22-
23-
#### Adapters
24-
- **@isotrieve/adapters-openai**: OpenAI embeddings support
25-
- text-embedding-3-small (1536D)
26-
- text-embedding-3-large (3072D)
27-
- text-embedding-ada-002 (1536D)
28-
29-
- **@isotrieve/adapters-voyage**: Voyage AI embeddings support
30-
- voyage-2 (1024D)
31-
- voyage-large-2 (1536D)
32-
- voyage-code-2 (1536D)
33-
34-
- **@isotrieve/adapters-cohere**: Cohere embeddings support
35-
- embed-english-v3.0 (1024D)
36-
- embed-multilingual-v3.0 (1024D)
37-
- embed-english-light-v3.0 (384D)
38-
- embed-multilingual-light-v3.0 (384D)
39-
40-
- **@isotrieve/adapters-huggingface**: Local inference support
41-
- Xenova/all-MiniLM-L6-v2 (384D)
42-
- Xenova/all-mpnet-base-v2 (768D)
43-
- Xenova/bge-small-en-v1.5 (384D)
44-
- Xenova/bge-base-en-v1.5 (768D)
45-
46-
#### Examples
47-
- Basic transfer example
48-
- Multi-agent chat example
49-
- Custom adapter example
50-
51-
#### Documentation
52-
- Getting started guide
53-
- Complete API reference
54-
- Protocol specification v1.0
55-
- Contributing guidelines
56-
57-
### Features
58-
59-
- **2x Better Semantic Preservation**: Validated 97% fidelity vs 43% text baseline
60-
- **Provider-Agnostic**: Works with any embedding API
61-
- **Production-Ready**: Validated on 300k vocabulary
62-
- **Lightweight**: < 1ms transfer latency
63-
- **Type-Safe**: Full TypeScript support
64-
- **Zero Dependencies**: Core package has no external dependencies
65-
66-
### Performance
67-
68-
- Calibration: 2-5 seconds for 1000 items
69-
- Transfer: < 1ms per embedding
70-
- Memory: O(D²) for transfer matrix
71-
- Quality: 0.80-0.97 cosine similarity
72-
73-
### Validated On
74-
75-
- 300k training vocabulary
76-
- 30k validation vocabulary
77-
- 10k test corpus
78-
- Multiple embedding model pairs
79-
- Cross-dimensional transfers (384D ↔ 768D, 1536D ↔ 3072D)
80-
81-
## [Unreleased]
82-
83-
### Planned
84-
85-
- Batch transfer optimization
86-
- Matrix compression (quantization)
87-
- Incremental calibration
88-
- Multi-hop transfer (A → B → C)
89-
- Neural transfer functions
90-
- WebAssembly acceleration
91-
- Browser support improvements
92-
- Additional adapters (Anthropic, Azure, AWS)
93-
94-
---
12+
#### Binary format v2
13+
- **8-byte header padding**: JSON header padded to 8-byte boundary for zero-copy Float64Array views
14+
- **CRC32 checksum**: CRC32 over entire file (excluding checksum field) for corruption detection
15+
- **Strict reader**: unknown header keys throw, missing required keys throw (prevents silent empty matrices)
16+
- **Header length cap**: headerLen validated against 1MB ceiling before allocation (DoS mitigation)
17+
- **Payload size assertion**: rows × cols × 8 must equal remaining bytes exactly (catches truncation at format layer)
18+
- **Endianness assertion**: module-init check that platform is LE (documented as format requirement)
19+
- **Prototype pollution fix**: normalizeHeaderKeys uses Object.create(null) to prevent __proto__ injection
9520

96-
## Version Support
97-
98-
| Version | Status | Support Until |
99-
|---------|--------|---------------|
100-
| 1.0.x | Active | TBD |
101-
102-
## Migration Guides
103-
104-
### From Python Implementation
105-
106-
The NPM package maintains API compatibility with the Python proof-of-concept:
107-
108-
**Python:**
109-
```python
110-
from protocol import ProtocolHandler
111-
112-
agent = ProtocolHandler("agent_a", embedder, "model", 384)
113-
transfer_matrix = agent.calibrate(partner, train_vocab, val_vocab)
114-
transfer = agent.transfer_to("agent_b", text)
115-
```
116-
117-
**TypeScript:**
118-
```typescript
119-
import { Isotrieve } from '@isotrieve/core';
120-
121-
const agent = new Isotrieve({ embedder });
122-
const result = await agent.calibrateWith(partner, { vocabularySize: 1000 });
123-
const transfer = await agent.transferTo(partner, embedding);
124-
```
125-
126-
## Breaking Changes
127-
128-
None (initial release)
129-
130-
## Security
131-
132-
- No known vulnerabilities
133-
- Dependencies regularly updated
134-
- Security audits planned for v1.1
135-
136-
## Credits
137-
138-
Based on research validating Agent Embedding Communication Protocol (Isotrieve):
139-
- Original Python implementation: [protocol.py](../protocol.py)
140-
- Research summary: [ENHANCED_SUMMARY.md](../ENHANCED_SUMMARY.md)
141-
- Protocol specification: [protocol_spec.md](../protocol_spec.md)
142-
143-
## License
144-
145-
MIT License - See [LICENSE](LICENSE) file for details
21+
#### Core Package (@isotrieve/core)
22+
- **Mapping types**: RidgeMapping, OrthogonalProcrustesMapping, ProcrustesDiagMapping, LowRankAffineMapping, ExternalMapping
23+
- **Binary format**: `.isotrieve` file read/write, cross-compatible with Python's isotrieve v2 format
24+
- **Quality gate**: `QualityGate` with isotonic regression model (gate_model_v1.json shared with Python)
25+
- **Score recalibration**: `ScoreRecalibrator` with PAVA isotonic regression
26+
- **Calibration planning**: `planCalibration`, `recommendK`
27+
- **Reranking**: `ConfidenceScorer`, `confidenceSummary`
28+
- **Migration**: `migrateStore` with batch processing, manifest, resumability
29+
- **Serve**: `QueryAdapter`, `cslsScores`, `mergeResults`
30+
- **Math**: SVD (one-sided Jacobi with m<n transpose fix), ridge regression with GCV alpha, matrix operations, cosine similarity, L2 normalization
31+
- **Tests**: 268 tests across 8 suites (linalg, normalize/metrics, errors, mappings, quality, correctness, cross-compat, stress)
32+
33+
### Notes
34+
- This is the first release of the new embedding-migration architecture for TypeScript
35+
- The old protocol code (`Isotrieve`, `IsotrieveNegotiator`, `protocol.ts`, `negotiation.ts`) has been removed from `@isotrieve/core`
36+
- Adapter packages (`adapters-openai`, `adapters-voyage`, `adapters-cohere`, `adapters-huggingface`) still reference the old API and will be updated in a future release
37+
- This package is pre-1.0. APIs may change between minor versions.
38+
- v2 format is not backward-compatible with v1 readers; v1 files can still be loaded

‎isotrieve-npm/README.md‎

Lines changed: 19 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,31 @@
1-
# Isotrieve - Agent Embedding Communication Protocol
1+
# Isotrieve — NPM packages
22

3-
> **⚠️ Historical/Experimental Package**
4-
> This NPM package is the original protocol prototype. The actively maintained, benchmark-validated project is [`isotrieve-python/`](../isotrieve-python/) — available on [PyPI as `isotrieve`](https://pypi.org/project/isotrieve/). This package is not actively maintained.
3+
> **Pre-1.0 / Beta** — The TypeScript packages are ports of the Python [`isotrieve`](https://pypi.org/project/isotrieve/) package under active development. The Python package is the mature, benchmark-validated implementation. Do not depend on these packages in production until the production readiness plan (see root README) is closed.
54
6-
Production-ready NPM package for semantic communication between agents using different embedding models.
7-
8-
## What is Isotrieve?
9-
10-
Isotrieve enables agents with different embedding models to communicate semantic information directly through learned transfer matrices, achieving **2x better semantic preservation** compared to text serialization.
11-
12-
## Quick Start
13-
14-
```bash
15-
npm install @isotrieve/core @isotrieve/adapters-openai
16-
```
17-
18-
```typescript
19-
import { Isotrieve } from '@isotrieve/core';
20-
import { OpenAIAdapter } from '@isotrieve/adapters-openai';
21-
22-
// Initialize agents
23-
const agent1 = new Isotrieve({
24-
embedder: new OpenAIAdapter({
25-
apiKey: process.env.OPENAI_KEY,
26-
model: 'text-embedding-3-large'
27-
})
28-
});
29-
30-
const agent2 = new Isotrieve({
31-
embedder: new OpenAIAdapter({
32-
apiKey: process.env.OPENAI_KEY,
33-
model: 'text-embedding-3-small'
34-
})
35-
});
36-
37-
// Calibrate (one-time setup)
38-
await agent1.calibrateWith(agent2);
39-
40-
// Transfer embeddings
41-
const embedding = await agent1.embed("Complex technical state");
42-
const transferred = await agent1.transferTo(agent2, embedding);
43-
44-
// Agent 2 uses transferred embedding natively
45-
const similar = await agent2.findSimilar(transferred, knowledgeBase);
46-
```
47-
48-
### Auto-Negotiation (NEW)
49-
50-
Isotrieve now automatically detects if both agents support the protocol and falls back to text if needed:
5+
## Packages
516

52-
```typescript
53-
import { Isotrieve, IsotrieveNegotiator } from '@isotrieve/core';
54-
import { OpenAIAdapter } from '@isotrieve/adapters-openai';
7+
| Package | Description | Status |
8+
|---|---|---|
9+
| [`@isotrieve/core`](./packages/core/) | Mapping, quality gate, migration, recalibration, serve | Beta |
10+
| `@isotrieve/adapters-openai` | OpenAI embedding provider | Legacy (old protocol API) |
11+
| `@isotrieve/adapters-voyage` | Voyage AI embedding provider | Legacy (old protocol API) |
12+
| `@isotrieve/adapters-cohere` | Cohere embedding provider | Legacy (old protocol API) |
13+
| `@isotrieve/adapters-huggingface` | HuggingFace embedding provider | Legacy (old protocol API) |
5514

56-
// Create your agents
57-
const agent1 = new Isotrieve({ embedder: new OpenAIAdapter({ apiKey: '...' }) });
58-
const agent2 = someOtherAgent; // Could be Isotrieve or not
15+
**Only `@isotrieve/core` has been ported to the new embedding-migration architecture.** The adapter packages still reference the old `Isotrieve` class and `IsotrieveNegotiator` protocol API. They will be updated or removed before any 1.0 release.
5916

60-
// Automatically negotiate and send message
61-
const result = await IsotrieveNegotiator.sendMessage(agent1, agent2, 'Hello!');
17+
## Which package is current?
6218

63-
// Isotrieve automatically:
64-
// ✓ Detects if both support Isotrieve → Uses Isotrieve with 97% fidelity
65-
// ✓ Detects if only one supports Isotrieve → Falls back to text
66-
// ✓ Shows clear warning when falling back
67-
// ✓ Returns result with method info
19+
**Use the Python package (`pip install isotrieve`) for production migrations.** The TypeScript packages are a work in progress. See the root [README.md](../README.md) for the full production readiness plan.
6820

69-
if (result.method === 'isotrieve') {
70-
console.log(`✓ Using Isotrieve with ${(result.expectedSimilarity! * 100).toFixed(1)}% fidelity`);
71-
} else {
72-
console.log(`⚠️ Using text: ${result.fallbackReason}`);
73-
}
74-
```
21+
## Development
7522

76-
**Example Output:**
77-
```
78-
# Both support Isotrieve:
79-
Both agents support Isotrieve. Calibrating...
80-
✓ Isotrieve enabled with 97.3% semantic fidelity
81-
82-
# Only one supports Isotrieve:
83-
⚠️ Isotrieve not available: Agent 2 does not support Isotrieve. Falling back to text communication.
23+
```bash
24+
npm install
25+
npm run build
26+
npm test
8427
```
8528

86-
## Features
87-
88-
- **2x Better Semantic Preservation** vs text round-trip
89-
- **Provider-Agnostic** - Works with OpenAI, Anthropic, Cohere, HuggingFace
90-
- **Quality Monitoring** - Automatic quality tracking with fallback
91-
- **Lightweight** - Millisecond-level transfer latency
92-
- **Production-Ready** - Validated on 300k vocabulary, 97% fidelity
93-
94-
## Packages
95-
96-
- `@isotrieve/core` - Core protocol implementation
97-
- `@isotrieve/adapters-openai` - OpenAI embeddings adapter
98-
- `@isotrieve/adapters-voyage` - Voyage AI adapter
99-
- `@isotrieve/adapters-cohere` - Cohere adapter
100-
- `@isotrieve/adapters-huggingface` - HuggingFace adapter
101-
102-
## Documentation
103-
104-
- [Protocol Specification](./docs/protocol-spec.md)
105-
- [Getting Started Guide](./docs/getting-started.md)
106-
- [API Reference](./docs/api-reference.md)
107-
10829
## License
10930

110-
MIT
31+
Apache-2.0. See [LICENSE](../isotrieve-python/LICENSE).

‎isotrieve-npm/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "isotrieve-monorepo",
3-
"version": "1.0.0",
3+
"version": "0.1.0",
44
"private": true,
5-
"description": "Agent Embedding Communication Protocol - Production-ready NPM package",
5+
"description": "Embedding migration without re-embedding — TypeScript packages",
66
"workspaces": [
77
"packages/*"
88
],

0 commit comments

Comments
 (0)