### Install dependencies and start Playground Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/playground.md Installs local inference and server dependencies with the tested model constraints, then starts the Playground HTTP server. The Playground registers Qwen3-Embedding-0.6B and JevEmbed-Qwen3-Embedding-0.6B by default using their Hugging Face model IDs. This command works outside the source directory after installation. ```bash python -m pip install -e '.[local,server]' -c requirements-models-tested.txt python -m jevembed --playground ``` -------------------------------- ### Full installation from project root Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Creates a virtual environment, activates it, and installs the package with dependencies. Use Python 3.10-3.12. The requirements.txt includes local inference and HTTP dependencies with constraints in requirements-models-tested.txt. ```bash python -m venv .venv source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1 python -m pip install -r requirements.txt python -m pip install -e . --no-deps ``` -------------------------------- ### Install and run jevembed.synthesis CLI Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/synthesis.md Install the synthesis extra and run the CLI. The first command installs the package with the synthesis extra. The second validates the configuration without contacting the service or creating output files, printing upper bounds on teacher calls, HTTP attempts, and requested completion tokens. The third runs the synthesis with a specified output directory. ```bash python -m pip install -e '.[synthesis]' python -m jevembed.synthesis --config configs/synthesis/choice-dinosaur.yaml --validate-only python -m jevembed.synthesis \ --config configs/synthesis/choice-dinosaur.yaml \ --output artifacts/synthesis/dinosaur ``` -------------------------------- ### Optional installation extras Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Install only the needed extras: core, HTTP/server, local inference, or development dependencies. The core imports and --explain require no model weights or service. ```bash python -m pip install -e . # Core, configuration, and explain python -m pip install -e '.[http,server]' # HTTP backend and API python -m pip install -e '.[local]' -c requirements-models-tested.txt python -m pip install -r requirements-dev.txt # Tests and builds, without model libraries ``` -------------------------------- ### Run CLM v0.1-8B example with JevEmbed Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/clm.md Loads the CLM v0.1-8B configuration and an example request, sets the model ID, then evaluates the request. Requires the configuration file and example JSON to be present. ```python import json from jevembed import JevEmbed, ModelConfig config = ModelConfig.load("configs/clm-v0.1-8b.yaml") with open("examples/official_choice_exchange.json", encoding="utf-8") as handle: request = json.load(handle) request["model"] = config.model_id client = JevEmbed(config=config) print(client.evaluate(request)) ``` -------------------------------- ### Start Playground with custom model configs Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/playground.md Starts the Playground with explicit configurations that replace the default models. Provide --config to choose your own models; explicit configurations replace the defaults. The server binds to 127.0.0.1 by default; use --host and --port if needed. ```bash python -m jevembed \ --config configs/qwen3-embedding-0.6b.yaml \ --config configs/jevembed-qwen3-embedding-0.6b.yaml \ --playground ``` -------------------------------- ### Start the JevEmbed HTTP server Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Starts the server with a model loaded and serves decisions over HTTP. Run from the project root. ```bash python -m jevembed \ --config configs/jevembed-qwen3-embedding-0.6b.yaml \ --serve ``` -------------------------------- ### Install development dependencies and run tests Source: https://github.com/hitsz-tmg/jevembed/blob/main/CONTRIBUTING.md Install the development dependencies and run the test suite from the repository root. Tests use fixtures and mock models without downloading model weights. Generated traces are saved under the ignored artifacts/ directory. ```bash python -m pip install -r requirements-dev.txt python -m pytest -q ``` -------------------------------- ### Install training extra with pip Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Installs the package with the training extra and pins model versions using the requirements file. The training extra adds PEFT 0.18.1, Accelerate 1.13.0, and Datasets 4.8.4 to the supported local inference stack. Loading adapters in an inference-only installation additionally requires `python -m pip install -e '.[adapter]'`. ```bash python -m pip install -e '.[train]' -c requirements-models-tested.txt ``` -------------------------------- ### Start server with multiple models Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Starts the server with multiple models by repeating --config. Each HTTP decision request must include a registered model ID or alias, even when only one model is loaded; responses use the canonical short ID. ```bash python -m jevembed \ --config configs/kalm-embedding-v2.5.yaml \ --config configs/qwen3-embedding-0.6b.yaml \ --serve ``` -------------------------------- ### Start JevEmbed decision server Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Starts the JevEmbed decision server from the repository root. It listens on 127.0.0.1:8000 by default; use --host and --port to change the bind address and port. Model weights load when first needed, so a successful model-list response does not mean inference has already loaded the weights. ```bash python -m jevembed --config configs/kalm-embedding-v2.5.yaml --serve ``` -------------------------------- ### Copy and edit http-example.yaml, then run JevEmbed CLI or server Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Commands to copy the example config, edit it for an upstream embeddings service, and run JevEmbed either for a single request or in serve mode. The upstream service must provide /v1/embeddings; JevEmbed's own --serve mode provides /v1/systemone and /v1/models instead. ```bash mkdir -p configs/local cp configs/http-example.yaml configs/local/embeddings.yaml # Edit configs/local/embeddings.yaml before running either command. python -m jevembed --config configs/local/embeddings.yaml --input your-request.json # Or expose decisions that use the upstream embeddings service: python -m jevembed --config configs/local/embeddings.yaml --serve ``` -------------------------------- ### Run JevEmbed benchmark with jevembed-benchmark Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Use this command to run versioned Choice, Score, and Noul JSONL benchmarks with one or more model configurations. The runner writes per-model results.json, an optional predictions.jsonl, and a comparison summary.json. The benchmark guide defines the input format, targets, metrics, and result layout. ```bash jevembed-benchmark --benchmark examples/benchmark/benchmark.json \ --config configs/jevembed-qwen3-embedding-0.6b.yaml --output results ``` -------------------------------- ### Create embedded FastAPI app with custom HTTP limits Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/runtime.md Python example showing how to pass explicit HTTP service limits when creating an embedded FastAPI application. Each worker process has its own limits and cache. ```python from jevembed.server import HTTPServiceLimits, create_app app = create_app(client, limits=HTTPServiceLimits(max_body_bytes=4 * 1024 * 1024, max_embedding_inputs=8192, max_concurrent_requests=8, body_read_timeout_seconds=15)) ``` -------------------------------- ### GET /v1/models Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Lists available models. This endpoint is provided by JevEmbed's own --serve mode. ```APIDOC ## GET /v1/models ### Description Lists the models available on the JevEmbed server. This endpoint is provided by JevEmbed's own --serve mode. ### Method GET ### Endpoint /v1/models ### Response #### Success Response (200) - **models** (array) - List of model IDs. #### Response Example { "models": [] } ``` -------------------------------- ### YAML configuration for externally fitted scoring parameters Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/calibration.md Example YAML configuration for externally fitted scoring parameters. These numbers are illustrative, not recommended. Fit each model, primitive, and Noul path independently and record the model revision, template, serialization, precision, evaluation dataset, and scoring method. ```yaml scoring: choice_temperature: 0.15 score_temperature: 0.2 noul_with_criteria: {slope: 5.0, intercept: -0.2} noul_without_criteria: {slope: 4.0, intercept: -2.0} calibration_status: externally_fitted calibration_record: model_revision: exact-commit-or-artifact-sha256 template_version: v1 serialization_version: configurable-text-v2 scoring_method: temperature-and-logistic validation_dataset: your-independent-held-out-dataset ``` -------------------------------- ### Evaluate JevEmbed-Data test split with evaluate_jevembed_data.py Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Install training dependencies and run the evaluation script on the held-out JevEmbed-Data test Parquet. The report includes hard-label accuracy for Choice, Score, and Noul, plus Score/Noul MAE and distribution metrics with denominators. For a trained adapter, pass --adapter-path and its base model's local weights with --model-path; save runtime results under the ignored artifacts/ directory. ```bash python -m pip install -e '.[train]' python scripts/evaluate_jevembed_data.py \ --config configs/kalm-embedding-v2.5.yaml \ --test-data path/to/JevEmbed-Data/data/test-00000-of-00001.parquet \ --device cuda --dtype bfloat16 \ --max-input-tokens 1024 --overflow-policy truncate \ --output artifacts/evaluations/kalm-test.json ``` -------------------------------- ### JevEmbed request contract JSON example Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/design.md Shows the required JSON structure for a JevEmbed request, including model, state, and questions with type, instructions, and criteria. The model must be registered; HTTP requires an explicit model, while Python calls may use the client's default. ```json { "model": "kalm-embedding-v2.5", "state": "Content to evaluate", "questions": { "question_id": { "type": "choice", "instructions": "Which option fits?", "criteria": {"a": "Description A", "b": "Description B"} } } } ``` -------------------------------- ### Evaluate JevEmbed Data with KaLM Configuration Source: https://github.com/hitsz-tmg/jevembed/blob/main/reports/JEVEMBED_DATA_TEST.md Run the test evaluator from the repository root to reproduce results for the KaLM base model. Requires JevEmbed and training dependencies installed. The command uses the KaLM config and specifies test data, model path, device, dtype, token limits, and output file. ```bash python scripts/evaluate_jevembed_data.py \ --config configs/kalm-embedding-v2.5.yaml \ --test-data path/to/JevEmbed-Data/data/test-00000-of-00001.parquet \ --model-path path/to/KaLM-embedding-multilingual-mini-instruct-v2.5 \ --device cuda --dtype bfloat16 \ --max-input-tokens 1024 --overflow-policy truncate \ --encode-batch-size 64 --chunk-questions 500 \ --output results/kalm-test.json ``` -------------------------------- ### Send Choice request with httpx Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Sends the same Choice request from Python using httpx. The timeout is the caller's wait limit and is independent of the server's request-body read timeout. Install httpx with the project's standard requirements or pip install -e '.[http]'. ```python import json from pathlib import Path import httpx request = json.loads(Path("examples/official_choice_exchange.json").read_text(encoding="utf-8")) response = httpx.post("http://127.0.0.1:8000/v1/systemone", json=request, timeout=300.0) response.raise_for_status() print(response.json()["answers"]["department"]["choice"]) ``` -------------------------------- ### GET /v1/models Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Lists the registered model IDs and aliases on the JevEmbed decision server. ```APIDOC ## [GET] /v1/models ### Description List the registered model IDs and aliases for the JevEmbed decision server. ### Method GET ### Endpoint /v1/models ### Response #### Success Response (200) - **object** (string) - Always "list". - **data** (array) - Array of objects, each with `id` and `aliases`. #### Response Example { "object": "list", "data": [ { "id": "kalm-embedding-v2.5", "aliases": [] } ] } ``` -------------------------------- ### Send Choice request with curl Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Sends a Choice request to /v1/systemone with curl. The response contains model, answers.department (including choice, probabilities, and confidence), and usage. The same endpoint accepts Score and Noul requests using the shared examples. ```bash curl -sS http://127.0.0.1:8000/v1/systemone \ -H 'Content-Type: application/json' \ --data-binary @- <<'JSON' { "model": "kalm-embedding-v2.5", "state": "My running shoes arrived in the wrong size. Can I swap them for a size 10?", "questions": { "department": { "type": "choice", "instructions": "Which team should handle this?", "criteria": { "returns": "Exchanges, wrong or damaged items", "shipping": "Delivery status, delays, lost packages", "billing": "Charges, invoices, payment problems" } } } } JSON ``` -------------------------------- ### JSONL row format for training records Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/synthesis.md Example JSONL row illustrating the output format. Each row contains id, group, request with state and fixed questions, and answers with hard labels. The group field equals task.id to keep job data together in group-held-out validation. ```json {"id":"risk-points-demo-000000","group":"risk-points-demo","request":{"state":"risk_points: 8","questions":{"risk":{"type":"score","instructions":"Choose level 0 for 0–3, level 1 for 4–7, and level 2 for 8–10 risk points.","criteria":["Low","Medium","High"]}}},"answers":{"risk":{"level":2}}} ``` -------------------------------- ### Choice: route an exchange request with kalm-embedding-v2.5 Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/examples-and-scoring.md Request and response for the Jev Choice example 'route an exchange request' using model kalm-embedding-v2.5. The request asks which department should handle an exchange; the response returns 'returns' with probability 0.793768 and confidence 0.413996. The response includes usage token counts. ```json { "model": "kalm-embedding-v2.5", "state": "My running shoes arrived in the wrong size. Can I swap them for a size 10?", "questions": { "department": { "type": "choice", "instructions": "Which team should handle this?", "criteria": { "returns": "Exchanges, wrong or damaged items", "shipping": "Delivery status, delays, lost packages", "billing": "Charges, invoices, payment problems" } } } } ``` ```json { "model": "kalm-embedding-v2.5", "answers": { "department": { "type": "choice", "probabilities": { "returns": 0.7937679922689964, "shipping": 0.131790116809968, "billing": 0.07444189092103566 }, "confidence": 0.4139963162182463, "choice": "returns" } }, "usage": { "input_tokens": 61, "output_tokens": 0 } } ``` -------------------------------- ### Reference check function for dinosaur example Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/synthesis.md Define a trusted deterministic rule as a Python function returning True only for a correct hard label. The runner calls it after schema and blind-teacher checks on deep copies; it never executes teacher-generated code. A non-boolean return or exception aborts with a sanitized error. ```python def check_dinosaur(state, answer, question): expected = "Jump" if state["distance_to_obstacle"] <= 5 else "Keep running" return answer["choice"] == expected ``` -------------------------------- ### Score: assess a Safari bug with kalm-embedding-v2.5 Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/examples-and-scoring.md Request and response for the Jev Score example 'assess a Safari bug' using model kalm-embedding-v2.5. The request asks to score the severity of a Safari crash; the response returns a score of 1.256149 with confidence 0.075796 and a legend mapping scores to criteria. The response includes usage token counts. ```json { "model": "kalm-embedding-v2.5", "state": "The export button crashes the settings page in Safari. It works in Chrome, but a few of our customers only use Safari.", "questions": { "bug_severity": { "type": "score", "instructions": "How severe is the reported issue?", "criteria": [ "Cosmetic; no impact to functionality", "Broken or degraded feature, but workaround exists", "Blocking issue; no workaround exists" ] } } } ``` ```json { "model": "kalm-embedding-v2.5", "answers": { "bug_severity": { "type": "score", "probabilities": { "0": 0.15376904118628926, "1": 0.43631340883021275, "2": 0.40991754998349794 }, "confidence": 0.07579551491122716, "score": 1.2561485087972086, "legend": { "0": "Cosmetic; no impact to functionality", "1": "Broken or degraded feature, but workaround exists", "2": "Blocking issue; no workaround exists" } } }, "usage": { "input_tokens": 62, "output_tokens": 0 } } ``` -------------------------------- ### Build wheel and source distribution Source: https://github.com/hitsz-tmg/jevembed/blob/main/CONTRIBUTING.md Build the wheel and source distribution before publishing a release. Run from the repository root. ```bash python -m build ``` -------------------------------- ### Use JevEmbed from Python Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Loads a config, creates a JevEmbed client, reads a request from a JSON file, and evaluates it. Prints the response. ```python import json from pathlib import Path from jevembed import JevEmbed, ModelConfig config = ModelConfig.load("configs/kalm-embedding-v2.5.yaml") client = JevEmbed(config=config) request = json.loads(Path("examples/official_noul_escalation.json").read_text(encoding="utf-8")) response = client.evaluate(request) print(response) ``` -------------------------------- ### Run benchmark with jevembed-benchmark CLI Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/benchmark.md Run the benchmark from the command line. Repeat --config to compare models. Use --limit N for a smoke test and --overwrite to replace an existing result. ```bash jevembed-benchmark \ --benchmark examples/benchmark/benchmark.json \ --config configs/jevembed-qwen3-embedding-0.6b.yaml \ --output results \ --save-predictions ``` -------------------------------- ### Run inference and resume training with jevembed Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Run inference with the adapter configuration, then resume training from a checkpoint. Resume requires a checkpoint-* directory directly inside the original output directory and matching settings/data, including the GPU count for distributed runs. The manifest records a SHA-256 fingerprint of the base checkpoint, tokenizer, configuration, and relevant model code files; changing any weight or tokenizer file prevents resume. ```bash python -m jevembed --config artifacts/lora/kalm/inference.yaml \ --input examples/official_choice_exchange.json python -m jevembed.training \ --config configs/kalm-embedding-v2.5.yaml \ --training-config configs/training/lora.yaml \ --train-data artifacts/open-jev/train.jsonl \ --eval-data artifacts/open-jev/validation.jsonl \ --output artifacts/lora/kalm \ --resume-from-checkpoint artifacts/lora/kalm/checkpoint-100 ``` -------------------------------- ### Copy public configuration to local directory Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/runtime.md Commands to create the local config directory and copy a public configuration file into it, as part of setting up local weights and offline use. ```bash mkdir -p configs/local cp configs/kalm-embedding-v2.5.yaml configs/local/kalm.yaml ``` -------------------------------- ### Inspect inputs and traces with explain() and evaluate_with_trace() Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Inspects inputs and traces. `explain()` compiles and renders inputs without loading model weights; `evaluate_with_trace()` runs inference and returns both the standard response and diagnostics. Traces include rendered inputs, similarities, cache activity, truncation records, backend metadata, token usage sources, and elapsed time. Keep traces outside standard Jev responses. ```python compiled = client.explain(request) result = client.evaluate_with_trace(request) response = result["response"] trace = result["trace"] ``` -------------------------------- ### system_one(state, questions, model) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Builds and evaluates a Jev request directly from Python values for state and questions. ```APIDOC ## system_one(state, questions, model) ### Description Builds a Jev request from Python values and evaluates it. Useful when the state and questions are already available as Python objects. ### Method Python method call ### Endpoint `client.system_one(state, questions, model)` ### Parameters #### Request Body - **state** (str) - Required - The state input for the request. - **questions** (dict) - Required - A dictionary of questions, each with type, instructions, and criteria. - **model** (str) - Optional - The model ID to use. If omitted, the first registered model is used. ### Request Example ```python response = client.system_one( state="hello", questions={ "greeting": { "type": "choice", "instructions": "Classify the message.", "criteria": {"greeting": "A greeting", "other": "Other content"}, } }, model="kalm-embedding-v2.5", ) ``` ### Response #### Success Response - **response** (dict) - The evaluation result, same as `evaluate()`. ``` -------------------------------- ### explain(request) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Compiles and renders inputs without loading model weights, useful for inspecting the request before evaluation. ```APIDOC ## explain(request) ### Description Compiles and renders inputs for a request without loading model weights. Useful for inspecting the compiled inputs before running inference. ### Method Python method call ### Endpoint `client.explain(request)` ### Parameters #### Request Body - **request** (dict) - Required - The Jev request to compile. ### Request Example ```python compiled = client.explain(request) ``` ### Response #### Success Response - **compiled** (object) - The compiled and rendered inputs. ``` -------------------------------- ### Train with torchrun on four GPUs Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Launches distributed training on four GPUs on one machine. batch_size is per GPU; effective question batch size is batch_size × gradient_accumulation_steps × number of GPUs. All ranks share validation work; only the main rank writes metrics, checkpoints, and the final adapter. Resume with the same number of GPUs. ```bash torchrun --standalone --nnodes=1 --nproc-per-node=4 -m jevembed.training \ --config configs/kalm-embedding-v2.5.yaml \ --training-config configs/training/lora.yaml \ --train-data artifacts/open-jev/train.jsonl \ --eval-data artifacts/open-jev/validation.jsonl \ --output artifacts/lora/kalm-4gpu ``` -------------------------------- ### Run a single request from the command line Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Runs a single request using the specified config and input file. Use this for one-off evaluations from the terminal. ```bash python -m jevembed --config configs/kalm-embedding-v2.5.yaml \ --input examples/official_choice_exchange.json ``` -------------------------------- ### Build a request with system_one() Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Builds a request in Python using `system_one()` when state and questions are already Python values. The `model` parameter is optional; if omitted, the first registered model is used. ```python response = client.system_one( state="hello", questions={ "greeting": { "type": "choice", "instructions": "Classify the message.", "criteria": {"greeting": "A greeting", "other": "Other content"}, } }, model="kalm-embedding-v2.5", ) ``` -------------------------------- ### Run benchmark with run_benchmark Python API Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/benchmark.md Run the benchmark from Python. Uses the same runner as the CLI. ```python from jevembed.benchmark import run_benchmark from jevembed.config import ModelConfig summary = run_benchmark( "examples/benchmark/benchmark.json", [ModelConfig.load("configs/jevembed-qwen3-embedding-0.6b.yaml")], "results", save_predictions=True, ) ``` -------------------------------- ### Evaluate a request with JevEmbed Source: https://github.com/hitsz-tmg/jevembed/blob/main/examples/README.md Loads a model configuration and a request JSON, sets the model field, then evaluates the request with JevEmbed. Run from the project root. The CLI uses the same request fields. ```python import json from jevembed import JevEmbed, ModelConfig config = ModelConfig.load("configs/qwen3-embedding-4b.yaml") with open("examples/official_noul_escalation.json", encoding="utf-8") as handle: request = json.load(handle) request["model"] = config.model_id client = JevEmbed(config=config) print(client.evaluate(request)) ``` -------------------------------- ### evaluate(request) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Loads a model configuration and evaluates a Jev request, returning a dictionary with model ID, answers, and token usage. ```APIDOC ## evaluate(request) ### Description Evaluates a Jev request using the configured model and returns a plain dictionary containing the model ID, answers, and token usage. ### Method Python method call ### Endpoint `client.evaluate(request)` ### Parameters #### Request Body - **request** (dict) - Required - The Jev request to evaluate, typically loaded from a JSON file. ### Request Example ```python import json from pathlib import Path from jevembed import JevEmbed, ModelConfig config = ModelConfig.load("configs/kalm-embedding-v2.5.yaml") client = JevEmbed(config=config) request = json.loads(Path("examples/official_noul_escalation.json").read_text(encoding="utf-8")) response = client.evaluate(request) ``` ### Response #### Success Response - **response** (dict) - Contains the model ID, answers, and token usage. #### Response Example ```python # response is a plain dictionary with model ID, answers, and token usage ``` ``` -------------------------------- ### evaluate_with_trace(request) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Runs inference and returns both the standard response and a trace with diagnostics. ```APIDOC ## evaluate_with_trace(request) ### Description Runs inference and returns a dictionary containing the standard response and a trace with diagnostics. The trace includes rendered inputs, similarities, cache activity, truncation records, backend metadata, token usage sources, and elapsed time. ### Method Python method call ### Endpoint `client.evaluate_with_trace(request)` ### Parameters #### Request Body - **request** (dict) - Required - The Jev request to evaluate. ### Request Example ```python result = client.evaluate_with_trace(request) response = result["response"] trace = result["trace"] ``` ### Response #### Success Response - **response** (dict) - The standard evaluation response. - **trace** (dict) - Diagnostics including rendered inputs, similarities, cache activity, truncation records, backend metadata, token usage sources, and elapsed time. ``` -------------------------------- ### Convert Open-Jev dataset with jevembed.training.open_jev Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Downloads and converts the Open-Jev dataset to JevEmbed format. The optional HF_ENDPOINT export is only needed when the official endpoint is unavailable. The command preserves all 79,116 train and 3,723 validation rows by default. ```bash # Optional, when the official endpoint is unavailable: # export HF_ENDPOINT=https://hf-mirror.com python -m jevembed.training.open_jev --output artifacts/open-jev ``` -------------------------------- ### POST /v1/systemone Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Sends a Choice, Score, or Noul decision request to the JevEmbed decision server. ```APIDOC ## [POST] /v1/systemone ### Description Send a Choice, Score, or Noul decision request to the JevEmbed decision server. The request must include a registered model ID or alias. The response contains the model, answers, and usage. ### Method POST ### Endpoint /v1/systemone ### Parameters #### Request Body - **model** (string) - Required - Registered model ID or alias. - **state** (string) - Required - The input state text. - **questions** (object) - Required - Object mapping question names to question definitions. - **type** (string) - Required - Question type: "choice", "score", or "noul". - **instructions** (string) - Optional - Instructions for the question. - **criteria** (object) - Optional - Criteria for choice questions, mapping criterion names to descriptions. ### Request Example { "model": "kalm-embedding-v2.5", "state": "My running shoes arrived in the wrong size. Can I swap them for a size 10?", "questions": { "department": { "type": "choice", "instructions": "Which team should handle this?", "criteria": { "returns": "Exchanges, wrong or damaged items", "shipping": "Delivery status, delays, lost packages", "billing": "Charges, invoices, payment problems" } } } } ### Response #### Success Response (200) - **model** (string) - Canonical short ID of the model used. - **answers** (object) - Object mapping question names to answer objects. - **choice** (string) - The selected choice. - **probabilities** (object) - Probability distribution over choices. - **confidence** (number) - Confidence score. - **usage** (object) - Usage information. #### Response Example { "model": "kalm-embedding-v2.5", "answers": { "department": { "choice": "returns", "probabilities": { "returns": 0.9, "shipping": 0.05, "billing": 0.05 }, "confidence": 0.9 } }, "usage": {} } ``` -------------------------------- ### Evaluate a request with JevEmbed Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Loads a model configuration from a YAML file and evaluates a Jev request. The response is a plain dictionary containing the model ID, answers, and token usage. ```python import json from pathlib import Path from jevembed import JevEmbed, ModelConfig config = ModelConfig.load("configs/kalm-embedding-v2.5.yaml") client = JevEmbed(config=config) request = json.loads(Path("examples/official_noul_escalation.json").read_text(encoding="utf-8")) response = client.evaluate(request) ``` -------------------------------- ### benchmark.json manifest Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/benchmark.md Manifest file for a benchmark. Identifies the benchmark and its data file. All paths are relative to the manifest and must stay in its directory. ```json { "schema_version": "jevembed-benchmark-v1", "name": "example-decisions", "version": "1.0", "split": "test", "description": "Small Choice, Score, and Noul example.", "data": "cases.jsonl" } ``` -------------------------------- ### POST /v1/systemone Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md The main endpoint for JevEmbed decisions. It applies default limits per server process and returns errors for invalid requests, size violations, and busy slots. ```APIDOC ## POST /v1/systemone ### Description Processes a request for JevEmbed decisions. The endpoint applies default limits per server process and returns appropriate error codes for invalid requests, size violations, and busy slots. ### Method POST ### Endpoint /v1/systemone ### Parameters #### Request Body - **model** (string) - Required - The model ID to use, e.g., `embedding-service`. - **input** (object) - Required - The input data for the decision. ### Response #### Success Response (200) - **decisions** (array) - The decision results. #### Response Example { "decisions": [] } ### Error Handling - **422** - Invalid request. - **502** - Backend failure. - **413** - Size or work violation. - **429** - All request slots busy, with `Retry-After: 1`. - **408** - Body read timeout. ``` -------------------------------- ### JevEmbed(backend=backend, model="my-model", confidence_estimator=...) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Constructor for JevEmbed that allows injecting custom backends and confidence estimators. ```APIDOC ## JevEmbed(backend=backend, model="my-model", confidence_estimator=...) ### Description Creates a JevEmbed client with optional custom backend and confidence estimator. The backend must implement `encode(list[EmbeddingInput]) -> EmbeddingBatch`. The confidence estimator provides a custom confidence function. ### Method Python constructor ### Endpoint `JevEmbed(backend=backend, model="my-model", confidence_estimator=...)` ### Parameters #### Request Body - **backend** (object) - Optional - A custom backend implementing `encode(list[EmbeddingInput]) -> EmbeddingBatch`. - **model** (str) - Optional - The model ID to use with the custom backend. - **confidence_estimator** (callable) - Optional - A custom confidence function. ### Request Example ```python client = JevEmbed(backend=backend, model="my-model", confidence_estimator=confidence_func) ``` ### Response Returns a JevEmbed client instance. ``` -------------------------------- ### Benchmark output directory structure Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/benchmark.md Directory structure written by the runner for each model. predictions.jsonl is written only with --save-predictions. ```text results/example-decisions/ ├── summary.json └── jevembed-qwen3-embedding-0.6b/ ├── results.json └── predictions.jsonl ``` -------------------------------- ### List registered models with curl Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md Lists the registered model IDs and aliases. The response has "object": "list" and a data array of objects with id and aliases. ```bash curl -sS http://127.0.0.1:8000/v1/models ``` -------------------------------- ### Sharded data array in benchmark.json Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/benchmark.md Sharded data configuration. Files are read in listed order and must be unique JSONL files. ```json "data": ["cases-00000.jsonl", "cases-00001.jsonl", "cases-00002.jsonl"] ``` -------------------------------- ### register(config) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Registers a model configuration with the client, allowing selection by the request's `model` field. ```APIDOC ## register(config) ### Description Registers a model configuration with the client. After registration, the model can be selected via the request's `model` field. If no model is specified, the first registered model is used. ### Method Python method call ### Endpoint `client.register(config)` ### Parameters #### Request Body - **config** (ModelConfig) - Required - The model configuration to register. ### Request Example ```python client = JevEmbed() client.register(ModelConfig.load("configs/kalm-embedding-v2.5.yaml")) client.register(ModelConfig.load("configs/qwen3-embedding-0.6b.yaml")) request["model"] = "qwen3-embedding-0.6b" response = client.evaluate(request) ``` ### Response No explicit return value documented. ``` -------------------------------- ### Set model directory and offline loading policy in local config Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/runtime.md YAML configuration snippet to set the model path and enable local-only loading. Relative paths resolve from the command's working directory. Run with --config configs/local/kalm.yaml. ```yaml model_name_or_path: ./models/KaLM-embedding-multilingual-mini-instruct-v2.5 local_files_only: true ``` -------------------------------- ### Register multiple models and select by model field Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Registers multiple model configurations and selects one via the request's `model` field. Python calls may omit `model` to use the first registered model; HTTP requests must specify a registered model ID or alias. ```python client = JevEmbed() client.register(ModelConfig.load("configs/kalm-embedding-v2.5.yaml")) client.register(ModelConfig.load("configs/qwen3-embedding-0.6b.yaml")) request["model"] = "qwen3-embedding-0.6b" response = client.evaluate(request) ``` -------------------------------- ### Exact Noul label quotas YAML configuration Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/synthesis.md Use this YAML to request exact counts for Noul labels. The map must include every label and sum to generation.count; zero counts are allowed. Omitting quotas preserves unconstrained generation. ```yaml generation: count: 10 label_quotas: 'true': 5 'false': 5 ``` -------------------------------- ### EmbeddingBackend protocol definition Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/design.md Defines the protocol for custom backends. Implement encode(list[EmbeddingInput]) -> EmbeddingBatch. Inputs carry role, instruction, and text; batches carry vectors, token usage, and usage provenance. Backends can be injected with JevEmbed(backend=backend, model="my-model"). ```python class EmbeddingBackend(Protocol): def encode(self, items: list[EmbeddingInput]) -> EmbeddingBatch: ... ``` -------------------------------- ### Send a Choice request via curl Source: https://github.com/hitsz-tmg/jevembed/blob/main/README.md Sends a Choice request to the running server using curl. The JSON body includes model, state, and questions with criteria. ```bash curl -sS http://127.0.0.1:8000/v1/systemone \ -H 'Content-Type: application/json' \ --data-binary @- <<'JSON' { "model": "jevembed-qwen3-embedding-0.6b", "state": "My running shoes arrived in the wrong size. Can I swap them for a size 10?", "questions": { "department": { "type": "choice", "instructions": "Which team should handle this?", "criteria": { "returns": "Exchanges, wrong or damaged items", "shipping": "Delivery status, delays, lost packages", "billing": "Charges, invoices, payment problems" } } } } JSON ``` -------------------------------- ### Scoring formulas for cosine, softmax, choice, score, and confidence Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/design.md Formulas for computing cosine similarity, stable softmax, choice via argmax, weighted score, and confidence based on entropy. Temperatures are finite and positive with defaults of 0.1 for Choice and Score, and 0.01 for CLM. Confidence is clamped to [0,1] and equals 1 for K=1. ```text s_i = cosine(query, document_i) p_i = stable_softmax(s_i / temperature) choice = argmax(p_i) score = sum(i * p_i) confidence = 1 - entropy(p) / log(K) # default ``` -------------------------------- ### POST /v1/embeddings (external service) Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/http.md JevEmbed sends batches to this endpoint on an external embeddings service. It is not provided by JevEmbed's own server. ```APIDOC ## POST /v1/embeddings ### Description JevEmbed sends batches of embedding inputs to this endpoint on an external embeddings service. The upstream service must provide this endpoint and reject overlong inputs. ### Method POST ### Endpoint /v1/embeddings ### Parameters #### Request Body - **model** (string) - Required - The model ID accepted by the upstream service. - **input** (array) - Required - List of embedding inputs. ### Response #### Success Response (200) - **usage** (object) - Required when `usage_mode: strict` - Must include `prompt_tokens`. - **data** (array) - Required - List of indexed float embeddings. #### Response Example { "usage": { "prompt_tokens": 0 }, "data": [] } ``` -------------------------------- ### Convert JevEmbed-Data train split to JSONL Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Stream-converts the train split of JevEmbed-Data from Parquet to supervised JSONL, writing to `artifacts/jevembed-data/train.jsonl`. Use this file with `--train-data artifacts/jevembed-data/train.jsonl`. The published dataset has no validation split; omit `--eval-data` when using its entire train split. ```python import json from pathlib import Path from datasets import load_dataset path = Path("artifacts/jevembed-data/train.jsonl") path.parent.mkdir(parents=True, exist_ok=True) with path.open("w", encoding="utf-8") as output: for row in load_dataset("HIT-TMG/JevEmbed-Data", split="train", streaming=True): record = {"id": row["id"], "group": row["group"], "request": json.loads(row["request_json"]), "answers": json.loads(row["answers_json"])} output.write(json.dumps(record, ensure_ascii=False) + "\n") ``` -------------------------------- ### Clear cache and use custom backends Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/python-api.md Clears every in-memory embedding cache, or only one model's cache by passing the model ID. Custom backends implement `encode(list[EmbeddingInput]) -> EmbeddingBatch` and can be injected with `JevEmbed(backend=backend, model="my-model")`; pass `confidence_estimator` for a custom confidence function. ```python client.clear_cache() client.clear_cache("kalm-embedding-v2.5") ``` -------------------------------- ### Validate data contract with --validate-only Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/training.md Validates the data contract without loading weights. Use this to check structure and split isolation before training. Token lengths are not checked by --validate-only. ```bash python -m jevembed.training \ --config configs/kalm-embedding-v2.5.yaml \ --training-config configs/training/lora.yaml \ --train-data artifacts/open-jev/train.jsonl \ --eval-data artifacts/open-jev/validation.jsonl \ --output artifacts/lora/kalm --validate-only ``` -------------------------------- ### Noul retrieval query formulas Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/calibration.md Default Noul retrieval query formulas. The criteria path uses a difference of cosines; the without-criteria path uses a single cosine. Default parameters map to approximate output ranges [0.000000002, 0.999999998] and [0.000045, 0.999955] respectively. ```text with criteria: sigmoid(a_with * (cos(q_question_state, q_true_criterion) - cos(q_question_state, q_false_criterion)) + b_with) without criteria: sigmoid(a_without * cos(q_question, q_state) + b_without) ``` -------------------------------- ### Softmax scoring formulas for Choice and Score Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/calibration.md Numerically stable softmax used for Choice and Score scoring. Temperature must be finite and positive; lower temperatures concentrate probability without changing ranking. Confidence is defined as 1 for K=1. ```text p_i = softmax(cosine(query, candidate_i) / temperature) choice = argmax(p_i) score = sum(i * p_i) confidence = 1 - entropy(p) / log(K) # default ``` -------------------------------- ### Noul scoring formulas with and without criteria Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/design.md Formulas for Noul scoring with and without criteria. Both parameter pairs default to slope 10 and intercept 0. CLM uses a true-minus-false difference for both forms and configures slope 100. All mappings are uncalibrated. ```text Noul with criteria: sigmoid(a_with * (cosine(q_question_state, q_true_criterion) - cosine(q_question_state, q_false_criterion)) + b_with) Noul without criteria: sigmoid(a_without * cosine(q_question, q_state) + b_without) ``` -------------------------------- ### Noul response with scores for human escalation and repeat contact Source: https://github.com/hitsz-tmg/jevembed/blob/main/docs/examples-and-scoring.md JSON response from kalm-embedding-v2.5 with noul scores for both questions. The criteria-free path compares the question with the state; the other compares true and false criteria. Both outputs exceed 0.5, but high state/question similarity is not a calibrated probability of agreement. ```json { "model": "kalm-embedding-v2.5", "answers": { "is_human_escalation": { "type": "noul", "noul": 0.9998150635615807 }, "is_repeat_contact": { "type": "noul", "noul": 0.5205740521193529 } }, "usage": { "input_tokens": 136, "output_tokens": 0 } } ```