About the implementation and examples

Engineering notes draw on author-supplied MailTrace development reports through 13 October 2026. They describe the documented revision, including local work, rather than independently verified live deployment. Experiment designs and architecture proposals describe work to evaluate. Examples are educational, use synthetic data and are not copied production code.

Index prepared passages, not an undifferentiated mailbox

The supplied development report describes case-scoped, versioned embedding sets using text-embedding-3-small with 1,536 dimensions. Searchable chunks retain typed source identities and hashes. This allows a retrieved passage to be connected back to an email or another eligible evidence item.

Indexing should happen after eligibility and preparation checks. Excluded evidence, foreign-case documents and unsupported media should not enter a search merely because a vector exists somewhere. A query result must be checked against the current evidence scope as well as the index that produced it.

Similarity is geometry, not a probability

Cosine similarity compares vector direction. The miniature vectors below are synthetic and make no provider call. They illustrate the calculation only; their numbers are not a quality result for MailTrace or for an embedding model.

python · Synthetic cosine calculation; actual configured vectors contain 1,536 values.
from math import isfinite, sqrt

def cosine(a, b):
    if not a or len(a) != len(b):
        raise ValueError("Incompatible vectors")
    if not all(isfinite(x) for x in (*a, *b)):
        raise ValueError("Non-finite vector")
    denominator = sqrt(sum(x*x for x in a) * sum(y*y for y in b))
    if denominator == 0:
        raise ValueError("Zero vector")
    return sum(x*y for x, y in zip(a, b)) / denominator

assert abs(cosine([1, 0], [1, 0]) - 1) < 1e-9
assert cosine([1, 0], [0, 1]) == 0

Evaluate the retrieval task before changing the model

A useful evaluation asks whether the supporting passage appears among a bounded number of results for realistic case questions. Include paraphrases, exact reference numbers, ambiguous requests and questions with no answer in the available evidence. Record false matches as well as missed passages.

If retrieval fails, inspect preparation, chunk boundaries, eligibility and query scope before assuming the model is too small. A stronger model cannot recover text that was never extracted, and a correct vector cannot repair a source filtered into the wrong case. The embedding integration is valuable when those surrounding contracts work.

References & further reading

Official documentation for the methods discussed. Application-specific details come from the development records described in the series note.

Browse the complete MailTrace series →