Open-weight JSON embedding model with CharCNN architecture and contrastive learning - training required
Project description
Custom JSON Embedding Model (from scratch)
A from-scratch character-CNN encoder trained with a contrastive objective to embed JSON records (devices, tickets, customers) into dense vectors for vector stores.
Features
- Char-level tokenizer (no external models)
- Multi-kernel 1D CNN + max-pooling
- Projection head to target dimension
- NT-Xent (InfoNCE) contrastive training with simple JSON augmentations
- JSON flattening utilities and CLI tools
- Conversation role tokens to structure prompts/responses
Model Card - Detailed model documentation, limitations, and usage guidelines
Installation
For Team Members (Recommended)
# Install directly from GitHub (requires access to the repo)
pip install git+https://github.com/PPT-ProdEng-Sandbox/ppt-json-embedding-model.git
# Or install a specific version/tag
pip install git+https://github.com/PPT-ProdEng-Sandbox/ppt-json-embedding-model.git@v0.1.5
# For development (editable install)
git clone https://github.com/PPT-ProdEng-Sandbox/ppt-json-embedding-model.git
cd ppt-json-embedding-model
pip install -e .
Using Pre-trained Model
Auto-download (Recommended):
# The model auto-downloads on first use - no manual download needed!
json-embed --input your-data.jsonl --output embeddings.npy
# Or search with auto-download
json-embed-search --pairs data.jsonl=embeddings.npy --query "find records" --topk 5
GitHub Authentication (For Private Repositories):
If you encounter 404 errors when downloading model weights, you may need to set up GitHub authentication:
# Set your GitHub Personal Access Token (PAT)
export GITHUB_TOKEN=your_personal_access_token
# Or alternatively
export GITHUB_PAT=your_personal_access_token
# Then run the commands as usual
json-embed --input your-data.jsonl --output embeddings.npy
To create a Personal Access Token:
- Go to GitHub Settings → Developer settings → Personal access tokens → Tokens (classic)
- Generate a new token with
reposcope for private repositories - Copy the token and set it as an environment variable
Manual download (Optional):
# Download the pre-trained model (model weights v0.1.4)
curl -L -o model.pt https://github.com/PPT-ProdEng-Sandbox/ppt-json-embedding-model/releases/download/v0.1.4/ppt-json-embedding-model-v0.1.4.pt
# Generate embeddings using downloaded model
json-embed --model model.pt --input your-data.jsonl --output embeddings.npy
Alternative: Local Development
# create venv (recommended)
python -m venv .venv
. .venv/Scripts/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
pip install -r requirements.txt
# or install as package
pip install -e .
# Train
json-embed-train --config config/default.yaml --data devices.jsonl tickets.jsonl customers.jsonl --out runs/exp1
# Embed (streaming, avoids OOM) - using trained model
json-embed --checkpoint runs/exp1/last.pt --input data/records.jsonl --output runs/exp1/records.npy --config config/default.yaml --batch-size 64 --limit 5000
# Embed using auto-downloaded pre-trained model
json-embed --input data/records.jsonl --output records.npy --batch-size 64
# Local search (cosine) across one or more JSONL=NPY pairs - with auto-download
json-embed-search --pairs data/records.jsonl=records.npy --query "find related records" --topk 5
# Prefilter exact fields before cosine (AND). Example: SerialNumber filter
json-embed-search --pairs data/qa-tickets_from_xlsx.fixed.jsonl=records.npy \
--where SerialNumber=APM00111003159 --query "Find tickets for this serial" --topk 5
Python API for Applications
For integrating into applications and agents, use the high-level Python API:
from embedding_model import JSONEmbeddingModel
# Initialize model (set JSON_EMBED_MODEL_PATH environment variable)
model = JSONEmbeddingModel("path/to/your/model.pt")
# Embed documents
documents = [
{"title": "Product A", "description": "High-quality widget", "price": 299},
{"title": "Service B", "description": "Professional installation", "price": 199}
]
embeddings = model.embed_documents(documents)
# Search documents
results = model.search(
query="affordable installation service",
documents=documents,
embeddings=embeddings,
top_k=5
)
for similarity, idx, doc in results:
print(f"Score: {similarity:.3f} | {doc['title']}")
Convenience functions for quick usage:
from embedding_model import search_documents
results = search_documents(
query="your search query",
documents=your_json_documents,
model_path="path/to/model.pt",
top_k=5
)
See examples/python_api_example.py for complete usage examples.
Benchmarking
Evaluate model performance with the benchmarking suite:
# Install benchmark dependencies
pip install -e ".[benchmark]"
# Run quick benchmark
python benchmarks/run_benchmarks.py --type quick
# Run comprehensive benchmark
python benchmarks/run_benchmarks.py --type comprehensive --model-path path/to/model.pt --data-dir data/
See benchmarks/README.md for detailed benchmarking documentation.
Data Format
- JSONL files containing one record per line.
- Records can be any JSON structure; flattening will convert to text.
- Example:
{"title": "Product A", "description": "High-quality widget", "price": 299}
Notes
- Steps per epoch ≈ ceil(total_records / batch_size). Use
max_stepsin config to cap. - CPU-only runs are slower; consider reducing
max_chars,batch_size, orconv_channels. - Use the cleaned
.fixed.jsonlyou trained on when embedding for consistency.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ppt_json_embedding_model-0.3.7.tar.gz.
File metadata
- Download URL: ppt_json_embedding_model-0.3.7.tar.gz
- Upload date:
- Size: 79.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45be10518eb2b73bdedfce2e04fba1faa56fd67724f8b79529b3f19c8786dd82
|
|
| MD5 |
62122219c41922fa7936c52eb6f17829
|
|
| BLAKE2b-256 |
f11a6a78cd5d14dc54102627d02787a0b0cf66c032a378a6c9cc2d10a6647c5b
|
File details
Details for the file ppt_json_embedding_model-0.3.7-py3-none-any.whl.
File metadata
- Download URL: ppt_json_embedding_model-0.3.7-py3-none-any.whl
- Upload date:
- Size: 39.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3e9d9346a4e2356397b83acb384e71cdc6142afffa476bff27ee3b0b618ec84
|
|
| MD5 |
912a91a4d8e5ce9b15aef7e641ffc802
|
|
| BLAKE2b-256 |
a1d4b8a95963bce872e4224b059508930901430482606edafb77e2b1b39f8951
|