hired.alignment.analyzer#
Library-mode autonomous alignment analysis, driven by an injected LLM.
The non-interactive counterpart of the hired-align skill: given a job
description’s text and a candidate’s facts, produce a draft
AlignmentReport that
save_alignment() finalizes and
persists. The pipeline is a grounded per-requirement judge:
decompose — the LLM splits the JD into atomic
Requirementrecords;retrieve — the most relevant facts are pulled from the knowledge base (lexical overlap by default, every fact when the KB fits in
k; injectretrieve=make_embedding_retriever()for semantic retrieval);quote-then-answer — the LLM must quote a verbatim span of a cited fact before it states a match;
gate — a quote that is not verbatim in the cited fact, a CONTRADICTED judgment not backed by a negation fact, or (with
nli) a quote that does not entail the requirement, drops the judgment to UNKNOWN: it becomes a question for the candidate, never an invented match or gap;aggregate — the verdict and fit band are computed deterministically from the records (
aggregate_verdict()). The LLM explains; it never sets the score.
Like LLMResumeAgent, the analyzer is lazy and injectable:
openai (the ai extra) is imported only when no client is given, and no
key is read at construction. client is anything exposing the OpenAI-style
chat.completions.create.
Functions
|
The verdict and fit band, computed from classified records alone. |
|
Analyse |
|
|
|
A semantic |
|
An |
|
True when |
|
The |
Classes
|
Draft an alignment report from JD text and facts, with an injected LLM. |
- class hired.alignment.analyzer.LLMAlignmentAnalyzer(*, model='gpt-4o-mini', client=None, api_key=None, n_samples=1, temperature=None, calibrator=None, retrieve=<function retrieve_facts>, top_k=5, nli=False, entails=None)[source]#
Bases:
objectDraft an alignment report from JD text and facts, with an injected LLM.
n_samples> 1 judges each requirement several times and feeds the agreement intoapply_calibration()(withcalibrator, the conformal ask/auto-decide rule).nliadds an entailment check on every confirmed quote;entailsreplaces the default (an LLM call) with any(premise, hypothesis) -> bool.retrievereplaces the lexicalretrieve_facts(), e.g. withmake_embedding_retriever()for semantic retrieval.>>> class _Fake: ... class chat: ... class completions: ... @staticmethod ... def create(**_): ... >>> LLMAlignmentAnalyzer(client=_Fake()).analyze(jd_text, facts)
- analyze(jd_text, facts, *, job_id='job', job_title='', company='', requirements=None)[source]#
A draft report: decompose (unless
requirementsgiven), judge, aggregate.- Return type:
- hired.alignment.analyzer.aggregate_verdict(records, *, apply_at=0.7, stretch_at=0.4, fit_bands=((0.85, FitBand.GREAT), (0.7, FitBand.GOOD), (0.5, FitBand.FAIR), (0.3, FitBand.WEAK), (0.0, FitBand.POOR)), class_weights={RequirementClass.DIFFERENTIATOR: 2.0, RequirementClass.GATE_KEEPER: 3.0, RequirementClass.VALUE_ADD: 1.0}, bucket_credit={Bucket.ADJACENT_TRANSFERABLE: 0.5, Bucket.GAP_HARD: 0.0, Bucket.GAP_LEARNABLE: 0.25, Bucket.STRONG_MATCH: 1.0})[source]#
The verdict and fit band, computed from classified records alone.
A blocking gap (a gate-keeper that is a hard gap or contradicted) means do not apply; otherwise the weighted coverage picks the recommendation. Confidence comes from how much of the JD is resolved, not from the LLM.
>>> from hired.alignment.base import MatchType >>> rec = classify(RequirementRecord(requirement=Requirement(text='Python'), ... match_state='confirmed', match_type=MatchType.DIRECT, candidate_level=4)) >>> verdict, band = aggregate_verdict([rec]) >>> verdict.recommendation.value, band.value, verdict.confidence.value ('apply', 'great', 'high')
- hired.alignment.analyzer.analyze_jd(workspace, jd_text, *, job_id, job_title='', analyzer=None, requirements=None)[source]#
Analyse
jd_textagainst the workspace candidate’s facts and persist it.The draft goes through
JDWorkspace.save_alignment()(finalize + archive + save), the one path from a draft to a stored report.analyzerdefaults to anLLMAlignmentAnalyzeron theaiextra.- Return type:
- hired.alignment.analyzer.coverage(records, *, class_weights={RequirementClass.DIFFERENTIATOR: 2.0, RequirementClass.GATE_KEEPER: 3.0, RequirementClass.VALUE_ADD: 1.0}, bucket_credit={Bucket.ADJACENT_TRANSFERABLE: 0.5, Bucket.GAP_HARD: 0.0, Bucket.GAP_LEARNABLE: 0.25, Bucket.STRONG_MATCH: 1.0})[source]#
(coverage, resolved_share): weighted bucket credit over resolved records, and the weighted share of records that are resolved at all.Records must be classified (see
classify()).
- hired.alignment.analyzer.make_embedding_retriever(embed=None, *, min_similarity=0.0)[source]#
A semantic
retrieveforLLMAlignmentAnalyzer: thekfacts most cosine-similar to the requirement, so adjacent skills (RabbitMQ for a Kafka requirement) reach the judge.embedmaps texts to vectors (defaultopenai_embed(), theaiextra). Fact vectors are cached by text, so each fact is embedded once per retriever.>>> vocab = ('kafka', 'rabbitmq', 'queue', 'french') >>> def embed(texts): # a fake: 'kafka' and 'rabbitmq' are both message queues ... return [[t.lower().count(w) + ('queue' == w) * ('kafka' in t.lower() or ... 'rabbitmq' in t.lower()) for w in vocab] for t in texts] >>> fs = [Fact(statement='Ran RabbitMQ in prod'), Fact(statement='Speaks French')] >>> retrieve = make_embedding_retriever(embed) >>> [f.statement for f in retrieve(Requirement(text='Kafka'), fs, k=1)] ['Ran RabbitMQ in prod']
- hired.alignment.analyzer.openai_embed(*, client=None, model='text-embedding-3-small')[source]#
An
Embedover OpenAI-styleclient.embeddings.create(aiextra).openaiis imported, and the client made, only at the first call.
- hired.alignment.analyzer.quote_is_grounded(quote, fact, *, min_words=2)[source]#
True when
quoteis a verbatim span (modulo case/whitespace) offact, at leastmin_wordslong.>>> quote_is_grounded('kafka CLUSTERS', Fact(statement='Ran Kafka clusters')) True >>> quote_is_grounded('Kafka expert', Fact(statement='Ran Kafka clusters')) False >>> quote_is_grounded('Kafka', Fact(statement='Ran Kafka clusters')) False
- Return type:
- hired.alignment.analyzer.retrieve_facts(requirement, facts, *, k=5, small_kb_passes_all=True)[source]#
The
kfacts sharing the most words with the requirement.Lexical, so it misses an adjacent skill named in different words (RabbitMQ for Kafka). When the whole knowledge base fits in
k(andsmall_kb_passes_all), every fact is passed, best overlap first, so the judge sees the adjacent skill anyway; a negation fact sharing no word is still dropped, so an unrelated “does not …” cannot back a contradiction. Otherwise facts sharing no word are dropped (none if none do). For large KBs, injectmake_embedding_retriever().>>> from hired.candidate.base import Fact >>> fs = [Fact(statement='Ran Kafka clusters'), Fact(statement='Speaks French')] >>> [f.statement for f in retrieve_facts(Requirement(text='Kafka streaming'), fs)] ['Ran Kafka clusters', 'Speaks French'] >>> [f.statement for f in retrieve_facts(Requirement(text='Kafka streaming'), fs, k=1)] ['Ran Kafka clusters']