File size: 2,318 Bytes
f109bf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
-- Synthetic David: separate AGENT and EVIDENCE vector spaces (pgvector)
CREATE EXTENSION IF NOT EXISTS vector;
CREATE EXTENSION IF NOT EXISTS pg_trgm;

-- AGENT INDEX — "Who should work?"
CREATE TABLE IF NOT EXISTS agent_registry (
  agent_id            text PRIMARY KEY,
  domain              text NOT NULL,
  capabilities        text[] NOT NULL DEFAULT '{}',
  languages           text[] NOT NULL DEFAULT '{}',
  input_types         text[] NOT NULL DEFAULT '{}',
  output_types        text[] NOT NULL DEFAULT '{}',
  required_evidence   text[] NOT NULL DEFAULT '{}',
  permissions         text[] NOT NULL DEFAULT '{}',
  risk_class          text NOT NULL CHECK (risk_class IN ('low','medium','high','critical')),
  dependencies        text[] NOT NULL DEFAULT '{}',
  execution_endpoint  text NOT NULL,
  control_plane       boolean NOT NULL DEFAULT false,
  embed_text          text NOT NULL,
  embedding           vector(1536),
  historical_success  real NOT NULL DEFAULT 0.0,
  updated_at          timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS agent_registry_embedding_hnsw
  ON agent_registry USING hnsw (embedding vector_cosine_ops);

CREATE INDEX IF NOT EXISTS agent_registry_capabilities_gin
  ON agent_registry USING gin (capabilities);

-- EVIDENCE INDEX — "What evidence should they use?"
CREATE TABLE IF NOT EXISTS evidence (
  evidence_id       text PRIMARY KEY,
  source_id         text NOT NULL,
  source_type       text NOT NULL,
  document_id       text,
  location          text,
  content           text NOT NULL,
  content_hash      text NOT NULL,
  embedding         vector(1536),
  content_tsv       tsvector GENERATED ALWAYS AS (to_tsvector('english', content)) STORED,
  source_authority  real NOT NULL DEFAULT 0.5,
  retrieved_by      text,
  retrieval_score   real,
  parent_evidence   text[] NOT NULL DEFAULT '{}',
  created_at        timestamptz NOT NULL DEFAULT now()
);

CREATE INDEX IF NOT EXISTS evidence_embedding_hnsw
  ON evidence USING hnsw (embedding vector_cosine_ops);

CREATE INDEX IF NOT EXISTS evidence_content_tsv_gin
  ON evidence USING gin (content_tsv);

-- Hybrid evidence retrieval sketch:
-- dense:  ORDER BY embedding <=> $query_vec
-- lexical: content_tsv @@ plainto_tsquery('english', $q)
-- then metadata + provenance filters, then rerank.