Give a search agent several prompts and score a role by its best one
Migration 14 moves each non-empty agents.intent into agent_prompts as one prompt named after the agent, with its cached vector, and drops the three intent columns. A role's fit is the maximum over the agent's prompts of the calibrated cosine, and scores.prompt names the prompt that won. The agents API takes prompts and still takes intent; the role endpoint serves the agent's score and prompt. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b6afe24eaa
commit
4e3c3f130e
9 files changed
+552
-127
No files matched your search
+44
-8
@@ -177,25 +177,34 @@ BEGIN
|
||||
SELECT RAISE(ABORT, 'application_events is append-only');
|
||||
END;
|
||||
|
||||
-- A search agent: a named saved search with its own intent text, gates and
|
||||
-- A search agent: a named saved search with its own prompts, gates and
|
||||
-- weights. gates is a list of {field, values, mode: require|prefer, weight}.
|
||||
-- intent_vec caches the intent's vector; intent_key is sha1 of the embedding
|
||||
-- model and the intent text, so editing either makes it stale. limits is how
|
||||
-- deep into this agent's ranking extract and summarise read, as JSON: a key
|
||||
-- it lacks means the `Limits` default.
|
||||
-- limits is how deep into this agent's ranking extract and summarise read,
|
||||
-- as JSON: a key it lacks means the `Limits` default.
|
||||
CREATE TABLE IF NOT EXISTS agents (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name TEXT NOT NULL UNIQUE,
|
||||
intent TEXT NOT NULL DEFAULT '',
|
||||
gates TEXT NOT NULL DEFAULT '[]',
|
||||
weights TEXT NOT NULL DEFAULT '{}',
|
||||
enabled INTEGER NOT NULL DEFAULT 1,
|
||||
created_at TEXT NOT NULL,
|
||||
intent_key TEXT NOT NULL DEFAULT '',
|
||||
intent_vec BLOB,
|
||||
limits TEXT NOT NULL DEFAULT '{}'
|
||||
);
|
||||
|
||||
-- What an agent looks for, as several named texts in order; a role's fit is
|
||||
-- its best prompt's. vec caches the text's vector and vec_key is sha1 of the
|
||||
-- embedding model and the text, so editing one prompt re-embeds that one.
|
||||
CREATE TABLE IF NOT EXISTS agent_prompts (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
position INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
text TEXT NOT NULL DEFAULT '',
|
||||
vec_key TEXT NOT NULL DEFAULT '',
|
||||
vec BLOB,
|
||||
PRIMARY KEY (agent_id, position),
|
||||
UNIQUE (agent_id, name COLLATE NOCASE)
|
||||
);
|
||||
|
||||
-- One agent's stance on a company: -1 hidden, 0 neutral, 1 liked, 2
|
||||
-- favourite. No row is 0, so the table holds only what somebody set. Per
|
||||
-- agent, because a company that is noise for one search is the target of
|
||||
@@ -220,12 +229,14 @@ CREATE TABLE IF NOT EXISTS role_votes (
|
||||
);
|
||||
|
||||
-- A role is scored per agent. A gated role keeps its row, with the reason.
|
||||
-- prompt names the agent's prompt that gave the fit, '' when fit did not count.
|
||||
CREATE TABLE IF NOT EXISTS scores (
|
||||
uid TEXT NOT NULL REFERENCES roles(uid) ON DELETE CASCADE,
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
score REAL NOT NULL DEFAULT 0,
|
||||
gated_reason TEXT NOT NULL DEFAULT '',
|
||||
scored_at TEXT NOT NULL,
|
||||
prompt TEXT NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (uid, agent_id)
|
||||
);
|
||||
|
||||
@@ -388,6 +399,31 @@ ALTER TABLE roles ADD COLUMN salary_text TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
(13, "roles.country recomputed from place for every not-yet-extracted role whose "
|
||||
"board gave none, country lookup fix", lambda conn: _recompute_country(conn)),
|
||||
# An agent's one intent becomes its first prompt, named after the agent,
|
||||
# with its cached vector: the key hashes the model and the text, which
|
||||
# are unchanged, so nothing is embedded again. An empty intent becomes no
|
||||
# prompt. The three columns are then dropped, as v6 dropped the ones it
|
||||
# moved.
|
||||
(14, "agent_prompts and scores.prompt: an agent holds several prompts, and a "
|
||||
"score names the one that gave the fit", """
|
||||
CREATE TABLE agent_prompts (
|
||||
agent_id INTEGER NOT NULL REFERENCES agents(id) ON DELETE CASCADE,
|
||||
position INTEGER NOT NULL,
|
||||
name TEXT NOT NULL,
|
||||
text TEXT NOT NULL DEFAULT '',
|
||||
vec_key TEXT NOT NULL DEFAULT '',
|
||||
vec BLOB,
|
||||
PRIMARY KEY (agent_id, position),
|
||||
UNIQUE (agent_id, name COLLATE NOCASE)
|
||||
);
|
||||
INSERT INTO agent_prompts (agent_id, position, name, text, vec_key, vec)
|
||||
SELECT id, 0, name, intent, intent_key, intent_vec FROM agents
|
||||
WHERE TRIM(intent, ' ' || char(9, 10, 13)) <> '';
|
||||
ALTER TABLE agents DROP COLUMN intent;
|
||||
ALTER TABLE agents DROP COLUMN intent_key;
|
||||
ALTER TABLE agents DROP COLUMN intent_vec;
|
||||
ALTER TABLE scores ADD COLUMN prompt TEXT NOT NULL DEFAULT '';
|
||||
"""),
|
||||
)
|
||||
|
||||
#: What a file created from `SCHEMA` today is already at.
|
||||
|
||||
Reference in new issue
Block a user