embedding

Policy fit

Run the policy fit we trained on your company

We trained a decision policy on your company: the questions your business actually asks of its messages, learned from examples drafted from what you do and what your competitors handle. It arrives as one file, your-company-policy.zip. This page takes you from that file to a working API in about ten minutes, on your own machine, with nothing leaving your network.

What is in the file

The trained layer for each question, the calibration that decides when an answer is sure enough to act on, the questions themselves, and a manifest with the SHA-256 of every file, signed by Embedding Space. Keep it as a .zip; there is nothing to unpack.

1. Load it with vegaml

bash
pip install "vegaml>=0.16"
python
import vegaml

policy = vegaml.load_policy("your-company-policy.zip", verify="signed")
print(policy.verified)
# {'status': 'signed', 'signed_by': 'Embedding Space (key 589c4677fa61c61c)', 'engine': 'matches'}

out = policy.decide("the message to decide")
print(out["route"])      # "auto" or "review"
print(out["answers"])

Before anything loads, vegaml checks every file against the manifest, the manifest's signature against Embedding Space's key, and that the reader on your machine is the one it was trained for. A changed file, a signature by anyone else, or the wrong reader is refused with the reason. The first run downloads the reader from Hugging Face; after that it works offline.

2. Read the answers

Each question comes back with its answer, a confidence, a route and a route_reason, and the message as a whole gets a route too. auto means the answer can be acted on without a person. review means a person should look, and the reason says why: the message is unlike anything the policy learned from, it could not narrow the answer to one option with enough confidence, or the question was not part of its training. Build on that one field: automate the auto messages, queue the rest for your team.

3. Serve it as your own API

A complete FastAPI server with API keys. Save it as server.py next to the .zip:

python
import hmac
import os
import threading

import vegaml
from fastapi import Depends, FastAPI, Header, HTTPException
from pydantic import BaseModel

POLICY = os.environ.get("POLICY_ZIP", "acme-policy.zip")
API_KEYS = [k.strip() for k in os.environ.get("API_KEYS", "").split(",") if k.strip()]

policy = vegaml.load_policy(POLICY, verify="signed")  # refuses a changed or unsigned file
lock = threading.Lock()                                # one model, one decision at a time

app = FastAPI(title="Decision policy")


def require_key(authorization: str = Header(default="")) -> None:
    token = authorization.removeprefix("Bearer ").strip()
    if not API_KEYS or not any(hmac.compare_digest(token, k) for k in API_KEYS):
        raise HTTPException(status_code=401, detail="missing or wrong API key")


class Ask(BaseModel):
    text: str


@app.get("/health")
def health() -> dict:
    return {"ok": True, "policy": policy.verified}


@app.post("/decide", dependencies=[Depends(require_key)])
def decide(body: Ask) -> dict:
    with lock:
        out = policy.decide(body.text)
    return {
        "route": out["route"],
        "answers": {q: {k: a.get(k) for k in ("choice", "score", "boolean", "confidence",
                                                 "prediction_set", "route", "route_reason")
                        if a.get(k) is not None}
                    for q, a in out["answers"].items()},
    }
bash
pip install "vegaml>=0.16" fastapi uvicorn

export POLICY_ZIP=your-company-policy.zip
export API_KEYS="$(openssl rand -hex 24)"     # keep this; it is your API key
uvicorn server:app --host 0.0.0.0 --port 8000

Call it:

bash
curl -X POST http://localhost:8000/decide \
  -H "Authorization: Bearer $API_KEYS" \
  -H "content-type: application/json" \
  -d '{"text": "I was charged twice, please refund one"}'

# {"route": "review",
#  "answers": {"queue": {"choice": "billing_account", "confidence": 0.98, "route": "auto", ...},
#              "urgency": {"score": 2, "confidence": 0.49, "route": "review",
#                          "route_reason": "it cannot narrow the answer to one option (1 or 2)"}, ...}}

Without a key, or with a wrong one, it answers 401. Keys are compared in constant time, and several can be set at once (comma separated) so you can rotate one without downtime. /health needs no key and reports whether the file was verified. If the server sits behind your own gateway and needs no keys, vegaml-serve --policy your-company-policy.zip (from pip install "vegaml[serve]") serves the same thing with no code.

4. Or run it in a container

dockerfile
FROM python:3.11-slim
RUN pip install --no-cache-dir "vegaml>=0.16" fastapi uvicorn
WORKDIR /app
COPY server.py your-company-policy.zip ./
ENV POLICY_ZIP=your-company-policy.zip
EXPOSE 8000
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8000"]
bash
docker build -t my-policy .
docker run -p 8000:8000 -e API_KEYS="your-long-random-key" \
  -v ~/.cache/huggingface:/root/.cache/huggingface my-policy

Mount the Hugging Face cache as a volume so the reader is downloaded once, not on every start. A CPU is enough for most queues; a GPU makes each decision faster.

Note

Make it yours

This file was trained on examples we drafted from public information about your company, so it starts strong and gets stronger with your own data. Send us a few hundred of your real messages with the answers your team gave, or upload them yourself in Embedding Studio, and the next file learns exactly how your team decides. Questions: nandakishor@embedding.in.