From 1a77c01e97bf740dc493104c18d437e6a7a4fbae Mon Sep 17 00:00:00 2001 From: Deodate-Lawson Date: Thu, 26 Nov 2026 17:55:44 -0500 Subject: [PATCH 1/3] Company search experiments: a brief in the buyers' language gains nothing on the app's built-in embedders E4 found that on Norwegian company texts a Norwegian brief finds 58.5 good companies in 100 checks against 25.0 for an English one, and that with an English brief the relevance-above-zero rule drops 40% and 89% of the good companies in two pools. That was measured with the small local model. Replayed through production's semanticRelevance on the app's two built-in embedding models (packages/llm/src/embeddings/index-registry.ts), the gap is gone: model English Norwegian difference (95%) nomic-embed-text (local) 25.0 58.5 +33.5 (-1.0 to +60.7) gemini-embedding-001 at 768 88.3 88.5 +0.2 (-3.8 to +4.4) text-embedding-3-large at 1536 74.5 69.9 -4.6 (-10.7 to +2.4) With an English brief the zero-score rule keeps 91% to 95% of the good companies on gemini-embedding-001 and 85% to 94% on text-embedding-3-large; with a Norwegian brief it keeps nearly the whole pool and stops filtering. So plan item 3 (translate the brief, or score against both) is not built, and the zero-score rule stays as it is. No product code changes. What is added is the replay that says so, in production-replay/: - vectors.ts, models.ts: cached vectors per embedding model, the models read from the registry the app resolves its embedder from. - record.ts: the one paid step. It sends nothing without record mode and a spend cap, prints its estimate first and never sends a text twice. - brief-language.ts and its test: the three Norwegian pools ranked by semanticRelevance with each brief, 20 seeds, and what the zero-score rule keeps. The test runs where the recordings are; elsewhere it checks the committed result file. - results/production-brief-language.json: one block per model, counts only. Co-Authored-By: Claude Fable 5.2 --- .../experiments/company-search/README.md | 22 +- .../production-replay/README.md | 78 ++ .../production-replay/brief-language.test.ts | 94 +++ .../production-replay/brief-language.ts | 183 +++++ .../production-replay/models.ts | 148 ++++ .../production-replay/record.ts | 86 +++ .../company-search/production-replay/run.ts | 138 ++++ .../production-replay/vectors.ts | 112 +++ .../results/production-brief-language.json | 672 ++++++++++++++++++ 9 files changed, 1531 insertions(+), 2 deletions(-) create mode 100644 pipelines/experiments/company-search/production-replay/README.md create mode 100644 pipelines/experiments/company-search/production-replay/brief-language.test.ts create mode 100644 pipelines/experiments/company-search/production-replay/brief-language.ts create mode 100644 pipelines/experiments/company-search/production-replay/models.ts create mode 100644 pipelines/experiments/company-search/production-replay/record.ts create mode 100644 pipelines/experiments/company-search/production-replay/run.ts create mode 100644 pipelines/experiments/company-search/production-replay/vectors.ts create mode 100644 pipelines/experiments/company-search/results/production-brief-language.json diff --git a/pipelines/experiments/company-search/README.md b/pipelines/experiments/company-search/README.md index 985d6c2e8..b90d20a12 100644 --- a/pipelines/experiments/company-search/README.md +++ b/pipelines/experiments/company-search/README.md @@ -65,8 +65,9 @@ a fresh recording gives slightly different numbers than the ones in Sources, all free and keyless: Photon and the OpenStreetMap API, Overpass, the Norwegian company register (Brønnøysundregistrene), the YC company directory, and the public pages of company websites. E4 also needs a local -Ollama with `nomic-embed-text` for embeddings. No paid search engine and no -paid model is called anywhere. +Ollama with `nomic-embed-text` for embeddings. No paid search engine is called +anywhere, and no paid model by E1 to E4; the recording script of +`production-replay/` is the exception (see "Production replay" below). How the recorder behaves towards those sources: @@ -169,3 +170,20 @@ bootstrap interval over seeds. answer: the letter "s" over all of Belgium, HTTP 503. It was asked again on 26 November, which added two places. The rest of that world, and the five other worlds, are as recorded on the 24th. + +## Production replay + +`production-replay/` puts the benchmark's pools through the ranking code +Prospects runs, on the app's two built-in embedding models. Its README has +the numbers; in short: + +- **The brief's language (after E4).** The gap between an English and a + Norwegian brief on Norwegian texts is the local model's: 25.0 against 58.5 + good companies in 100 checks there, 88.3 against 88.5 on + `gemini-embedding-001` and 74.5 against 69.9 on `text-embedding-3-large`. + Prospects does not translate the brief. + +It has its own runner (`production-replay/run.ts`); `run.ts` above replays E1 +to E4 only. Its recording script is the only paid call in this folder; it +needs record mode and a spend cap, and says what it will send before it sends +it. diff --git a/pipelines/experiments/company-search/production-replay/README.md b/pipelines/experiments/company-search/production-replay/README.md new file mode 100644 index 000000000..2d9a148a9 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/README.md @@ -0,0 +1,78 @@ +# Production replay + +E1 to E4 asked what could work. This folder asks what the code Prospects runs does: the benchmark's pools go through production's own ranking code (`pipelines/src/distribution/`), on the two embedding models built into the app (`packages/llm/src/embeddings/index-registry.ts`). + +| Replay | Question | Production code it runs | Result file | +| ------- | ----------------------------------------------------------------------------------- | ------------------------------------- | ---------------------------------------- | +| `brief` | On Norwegian company texts, does a Norwegian brief rank better than an English one? | `semanticRelevance` (today's ranking) | `results/production-brief-language.json` | + +The result file has one block per embedding model: + +| Model | What it is | +| ----------------------------- | ---------------------------------------------------------------------------------------- | +| `nomic-embed-text` | The local model E4 was recorded with. | +| `gemini-embedding-001@768` | Index `gemini-embedding-768`: the embedder the registry recommends for a new deployment. | +| `text-embedding-3-large@1536` | Index `legacy-openai-1536`: the default embedder. | + +## Results + +Recorded and replayed on 2026-11-26. All figures are means over E4's 20 seeds; intervals are 95%. + +### The brief's language (plan item 3): not built + +Good companies found in 100 checks by today's ranking, mean of the three Norwegian pools: + +| Embedding model | English brief | Norwegian brief | Norwegian minus English | +| ----------------------------- | ------------- | --------------- | ----------------------- | +| `nomic-embed-text` | 25.0 | 58.5 | +33.5 (−1.0 to +60.7) | +| `gemini-embedding-001@768` | 88.3 | 88.5 | +0.2 (−3.8 to +4.4) | +| `text-embedding-3-large@1536` | 74.5 | 69.9 | −4.6 (−10.7 to +2.4) | + +- **The gap is the local model's.** E4's finding reproduces exactly on `nomic-embed-text` and is gone on both built-in models: on `gemini-embedding-001` the two briefs are level, on `text-embedding-3-large` the Norwegian brief is behind. +- **Taking the higher of the two scores is the Norwegian brief.** A Norwegian text is closer to a Norwegian brief whatever it says, so the higher score is the Norwegian one for nearly every company and the two rows are identical. +- **The zero-score rule.** Production drops a company whose relevance is not above zero before any fit check. With an English brief it keeps this share of the good companies (coffee and tea, breweries, Bergen dentists): 93%, 60%, 11% on the local model; 91%, 94%, 95% on `gemini-embedding-001`; 85%, 93%, 94% on `text-embedding-3-large`. With a Norwegian brief it keeps 98% to 100% of them, and also 87% to 100% of the whole pool, so it stops filtering. + +So Prospects does not translate the brief: on the models it runs on there is nothing to gain, and a translated brief would switch the zero-score rule off. The rule is left as it is; what it costs on the built-in models is the 5% to 15% of good companies above. + +## Run it + +All commands from `pipelines/`. Replays are offline: recorded pools and cached vectors only. + +```sh +# The local model (a few seconds). +pnpm exec tsx experiments/company-search/production-replay/run.ts + +# One of the built-in models. +pnpm exec tsx experiments/company-search/production-replay/run.ts brief --model=gemini-embedding-001@768 +pnpm exec tsx experiments/company-search/production-replay/run.ts brief --model=text-embedding-3-large@1536 + +# The test: three seeds by default, all twenty (and a check against the result file) with the variable. +pnpm exec vitest run experiments/company-search/production-replay +COMPANY_SEARCH_REPLAY_SEEDS=20 pnpm exec vitest run experiments/company-search/production-replay +``` + +- A replay with all 20 seeds rewrites its model's block in the result file; two replays of the same recording write the same numbers. A run with fewer seeds (`--seeds=3`) prints its table and leaves the file alone. +- The recordings are not in git (see the folder's own README). Where they are absent, as in CI, the replay test is skipped and a small test checks the committed result file instead. + +## Record it (the paid step) + +One script sends texts to a paid model. It refuses to send anything without `COMPANY_SEARCH_BENCH_MODE=record` and a `--cap-usd`, prints its estimate first, stops when it is over the cap, and never sends a text twice. + +```sh +# Embeddings of the four pools, the briefs and the baseline. +COMPANY_SEARCH_BENCH_MODE=record pnpm exec tsx experiments/company-search/production-replay/record.ts \ + --model=gemini-embedding-001@768 --cap-usd=0.3 --via=openrouter +COMPANY_SEARCH_BENCH_MODE=record pnpm exec tsx experiments/company-search/production-replay/record.ts \ + --model=text-embedding-3-large@1536 --cap-usd=0.3 +``` + +- **What leaves the machine:** company names and their own activity texts, as the pools hold them. No address, phone or email. Sole proprietorships are often named after their owner. +- **Keys:** `GOOGLE_AI_API_KEY`, `EMBEDDING_API_KEY` or `OPENAI_API_KEY`, and `OPENROUTER_API_KEY`, from the environment. +- **`--via=openrouter`:** Google's own endpoint takes 100 texts a minute on its free tier. OpenRouter serves the same model at the same list price; eight texts recorded on both endpoints came back identical (cosine 1.000000). +- **What the recording of 2026-11-26 cost:** $0.26 (1.86 million tokens over the two models, all four pools). + +## Limits + +- **Three pools, one language pair.** The pools are Norwegian register entries and the briefs English and Norwegian; another language or another kind of text may behave differently. +- **The Norwegian briefs are E4's**, written by hand as a Norwegian seller would type them. A machine translation was not tried, since the hand-written one already gains nothing. +- **Labels are register codes**, as in E4: a company is good when the register files it under the segment's class. diff --git a/pipelines/experiments/company-search/production-replay/brief-language.test.ts b/pipelines/experiments/company-search/production-replay/brief-language.test.ts new file mode 100644 index 000000000..c1d7d32ef --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/brief-language.test.ts @@ -0,0 +1,94 @@ +/** + * The segment brief's language, on the benchmark's three Norwegian pools, + * through production's relevance and today's fixed order. + * + * On the local model a Norwegian brief finds more than twice as many good + * companies as an English one (E4's finding). On the app's two built-in + * embedding models it finds no more, which is why Prospects does not translate + * the brief. Both halves are checked here. + * + * Needs the recorded pools and vectors, which are not in git; without them the + * suite is skipped, so it runs on the machine that recorded them and not in + * CI. Three seeds by default; COMPANY_SEARCH_REPLAY_SEEDS=20 replays all + * twenty and then also checks the numbers against the committed results file. + */ +import { describe, expect, it } from "vitest"; + +import { SIMULATION } from "../e4-whom-to-check/config"; +import { briefTable, runBriefLanguageReplay } from "./brief-language"; +import { offlineEmbedder, REPLAY_MODELS } from "./models"; +import { readBriefResults } from "./run"; +import { LOCAL_MODEL, recordingsPresent } from "./vectors"; + +const seedCount = Math.min( + SIMULATION.seeds.length, + Math.max(1, Number(process.env.COMPANY_SEARCH_REPLAY_SEEDS ?? 3)) +); +const seeds = SIMULATION.seeds.slice(0, seedCount); +const full = seedCount === SIMULATION.seeds.length; +const production = REPLAY_MODELS.filter(model => model.indexKey !== null); + +describe.skipIf(!recordingsPresent())( + "production replay: the brief in the buyers' language", + () => { + it("reproduces E4's gap on the local model", async () => { + const summary = await runBriefLanguageReplay({ + embedder: offlineEmbedder(LOCAL_MODEL), + seeds, + }); + console.log(`\n${briefTable(LOCAL_MODEL, summary)}\n`); + // 25.0 against 58.5 with all twenty seeds. + expect(summary.norwegianMinusEnglish.found100.mean).toBeGreaterThan(20); + const kept = Object.fromEntries( + summary.perSegment.map(s => [s.segment, s.zeroScoreRule.english.goodKept]) + ); + // With an English brief the zero-score rule drops 40% and 89% of the good companies. + expect(kept["brreg-breweries"]).toBeLessThan(0.65); + expect(kept["brreg-dental-bergen"]).toBeLessThan(0.15); + if (full) expect(summary).toEqual(readBriefResults()?.byEmbedding[LOCAL_MODEL]); + }, 300_000); + + for (const model of production) { + it.skipIf(!recordingsPresent(model.id))( + `finds no such gap on ${model.id}`, + async () => { + const summary = await runBriefLanguageReplay({ + embedder: offlineEmbedder(model.id), + seeds, + }); + console.log(`\n${briefTable(model.id, summary)}\n`); + const gap = summary.norwegianMinusEnglish.found100; + // The Norwegian brief is not reliably better: the interval reaches zero or below. + expect(gap.mean).toBeLessThan(5); + expect(gap.lo).toBeLessThanOrEqual(0); + // And today's ranking is far better than on the local model either way. + expect(summary.overall.english.found100.mean).toBeGreaterThan(60); + // The zero-score rule keeps most good companies, English brief or not. + for (const segment of summary.perSegment) + expect( + segment.zeroScoreRule.english.goodKept, + `${segment.segment}: good companies the zero-score rule keeps` + ).toBeGreaterThan(0.8); + if (full) expect(summary).toEqual(readBriefResults()?.byEmbedding[model.id]); + }, + 300_000 + ); + } + } +); + +describe.skipIf(recordingsPresent())("production replay: the brief (recordings absent)", () => { + it("is skipped where the recorded pools are not on the machine", () => { + console.log( + "The company-search recordings are not here (COMPANY_SEARCH_BENCH_CACHE), so the replay did not run. Its last full result is results/production-brief-language.json." + ); + const results = readBriefResults(); + expect(results?.byEmbedding[LOCAL_MODEL]).toBeDefined(); + // What the decision rests on is in the committed file: no gap on the built-in models. + for (const model of production) { + const gap = results?.byEmbedding[model.id]?.norwegianMinusEnglish.found100; + expect(gap, `${model.id} in the results file`).toBeDefined(); + expect(gap!.mean).toBeLessThan(5); + } + }); +}); diff --git a/pipelines/experiments/company-search/production-replay/brief-language.ts b/pipelines/experiments/company-search/production-replay/brief-language.ts new file mode 100644 index 000000000..e2664f24e --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/brief-language.ts @@ -0,0 +1,183 @@ +/** + * "Write the segment brief in the buyers' language", replayed on production's + * embedding models. + * + * E4 found that on Norwegian company texts a Norwegian brief ranks far better + * than an English one (25.0 against 58.5 good companies in 100 checks), and + * that the relevance-above-zero rule then drops most good companies. That was + * measured with the small local model. Here the same three pools are ranked by + * production's own relevance (semanticRelevance) and checked from the top + * down, as production does, once per brief, on every embedding model whose + * vectors are on this machine. + * + * Three briefs per pool: English, Norwegian (E4's, as a Norwegian seller would + * type it), and the higher of the two scores per company. + */ +import { semanticRelevance, type EmbedTexts } from "../../../src/distribution/semantic"; +import { briefOf, segmentText } from "../e4-whom-to-check/briefs"; +import { SIMULATION } from "../e4-whom-to-check/config"; +import { createRecorder, loadPool, type LoadedPool } from "../e4-whom-to-check/data"; +import { REPORTED_SEGMENTS, type PoolId } from "../e4-whom-to-check/segments"; +import { subsampleOf } from "../e4-whom-to-check/simulate"; +import { clustered, difference, mean, round, type Spread } from "../e4-whom-to-check/stats"; +import type { ReplayEmbedder } from "./vectors"; + +export const BRIEFS = ["english", "norwegian", "higher"] as const; +export type Brief = (typeof BRIEFS)[number]; + +/** Checks after which the good companies found so far are counted. */ +export const BRIEF_BUDGETS = [25, 50, 100, 200] as const; +const BUDGETS = BRIEF_BUDGETS; +type Budget = `found${(typeof BUDGETS)[number]}`; + +export interface BriefSegment { + segment: string; + pool: string; + /** Companies in a seed's draw. */ + candidates: number; + /** Good companies in the whole pool. */ + good: number; + /** Per brief: mean over seeds of good companies in the first b checks. */ + found: Record>; + /** Per brief, whole pool: what production's relevance-above-zero rule keeps. */ + zeroScoreRule: Record; +} + +export interface BriefSummary { + seeds: number; + perSegment: BriefSegment[]; + /** Mean of the three pools, 95% interval over pools and seeds. */ + overall: Record>; + /** Norwegian brief minus English brief, paired by seed. */ + norwegianMinusEnglish: Record; +} + +export async function runBriefLanguageReplay(options: { + embedder: ReplayEmbedder; + seeds?: readonly number[]; +}): Promise { + const seeds = options.seeds ?? SIMULATION.seeds; + const embed: EmbedTexts = texts => options.embedder.embed(texts); + const recorder = createRecorder("replay"); + const pools = new Map(); + const perSegment: BriefSegment[] = []; + /** [brief][budget] → per segment → per seed. */ + const runs = Object.fromEntries( + BRIEFS.map(brief => [brief, BUDGETS.map(() => [] as number[][])]) + ) as Record; + + for (const segment of REPORTED_SEGMENTS.filter(s => s.norwegian)) { + let pool = pools.get(segment.pool); + if (!pool) { + pool = await loadPool(recorder, segment.pool); + pools.set(segment.pool, pool); + } + const labels = pool.labels(segment.label); + // Production's relevance of every company to each brief. + const english = await semanticRelevance( + embed, + briefOf(segmentText(segment, "en")), + pool.texts + ); + const norwegian = await semanticRelevance( + embed, + briefOf(segmentText(segment, "no")), + pool.texts + ); + const relevance: Record = { + english, + norwegian, + higher: english.map((score, i) => Math.max(score, norwegian[i]!)), + }; + const good = labels.reduce((sum, v) => sum + v, 0); + const found = {} as BriefSegment["found"]; + const zeroScoreRule = {} as BriefSegment["zeroScoreRule"]; + for (const brief of BRIEFS) { + const scores = relevance[brief]; + const bySeed: number[][] = []; + for (const seed of seeds) { + // The seed's draw of the pool, checked in today's order: relevance, + // ties in the draw's order. + const active = subsampleOf(pool.spec.id, pool.size, seed); + const order = Array.from({ length: active.length }, (_, a) => a) + .sort((a, b) => scores[active[b]!]! - scores[active[a]!]! || a - b) + .map(a => active[a]!); + const counts = BUDGETS.map(() => 0); + for (const [rank, index] of order.slice(0, BUDGETS.at(-1)).entries()) { + if (labels[index] !== 1) continue; + for (const [b, budget] of BUDGETS.entries()) if (rank < budget) counts[b]! += 1; + } + bySeed.push(counts); + } + found[brief] = Object.fromEntries( + BUDGETS.map((budget, b) => [ + `found${budget}`, + round(mean(bySeed.map(row => row[b]!)), 2), + ]) + ) as Record; + for (const [b] of BUDGETS.entries()) runs[brief][b]!.push(bySeed.map(row => row[b]!)); + let kept = 0; + let goodKept = 0; + for (const [i, score] of scores.entries()) { + if (!(score > 0)) continue; + kept += 1; + if (labels[i] === 1) goodKept += 1; + } + zeroScoreRule[brief] = { + poolKept: round(kept / pool.size, 3), + goodKept: round(goodKept / Math.max(1, good), 3), + }; + } + perSegment.push({ + segment: segment.id, + pool: segment.pool, + candidates: Math.round(pool.size * SIMULATION.subsample), + good, + found, + zeroScoreRule, + }); + } + + const overall = Object.fromEntries( + BRIEFS.map(brief => [ + brief, + Object.fromEntries( + BUDGETS.map((budget, b) => [`found${budget}`, clustered(runs[brief][b]!)]) + ), + ]) + ) as BriefSummary["overall"]; + const norwegianMinusEnglish = Object.fromEntries( + BUDGETS.map((budget, b) => [ + `found${budget}`, + clustered( + runs.norwegian[b]!.map((values, s) => difference(values, runs.english[b]![s]!)) + ), + ]) + ) as BriefSummary["norwegianMinusEnglish"]; + return { seeds: seeds.length, perSegment, overall, norwegianMinusEnglish }; +} + +const signed = (value: number): string => (value > 0 ? `+${value}` : String(value)); +const percent = (share: number): string => `${Math.round(share * 100)}%`; + +/** The table a run prints for one embedding model. */ +export function briefTable(model: string, summary: BriefSummary): string { + const lines = [ + `${model}: good companies found in 100 checks by today's ranking, per brief (${summary.seeds} seeds)`, + `${"segment".padEnd(22)}${"English".padStart(9)}${"Norwegian".padStart(11)}${"higher".padStart(8)} | zero-score rule keeps, English brief: pool / good`, + ]; + for (const s of summary.perSegment) { + lines.push( + `${s.segment.padEnd(22)}${String(s.found.english.found100).padStart(9)}${String(s.found.norwegian.found100).padStart(11)}${String(s.found.higher.found100).padStart(8)} | ${percent(s.zeroScoreRule.english.poolKept)} / ${percent(s.zeroScoreRule.english.goodKept)}` + ); + } + const o = summary.overall; + const d = summary.norwegianMinusEnglish.found100; + lines.push( + `${"three pools".padEnd(22)}${String(o.english.found100.mean).padStart(9)}${String(o.norwegian.found100.mean).padStart(11)}${String(o.higher.found100.mean).padStart(8)}` + ); + lines.push( + `Norwegian minus English, found in 100 checks: ${signed(d.mean)} (95% interval ${signed(d.lo)} to ${signed(d.hi)})` + ); + return lines.join("\n"); +} diff --git a/pipelines/experiments/company-search/production-replay/models.ts b/pipelines/experiments/company-search/production-replay/models.ts new file mode 100644 index 000000000..237f80085 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/models.ts @@ -0,0 +1,148 @@ +/** + * The embedding models the pools can be replayed with. The local one is what + * the benchmark was recorded with; the other two are the app's built-in + * indexes, read from the registry it resolves its embedder from, so a replay + * uses the model and the dimensions a deployment does. + */ +import { generateEmbeddings, resolveEmbeddingIndex } from "@launchstack/llm/embeddings"; + +import { cachedEmbedder, LOCAL_MODEL, type ReplayEmbedder } from "./vectors"; + +/** Where a recording sends its texts: an OpenAI-compatible embeddings endpoint. */ +export interface ReplayRoute { + baseUrl: string; + /** The model's id on that endpoint. */ + model: string; + /** Environment variables that may hold the key; the first one set wins. */ + keyEnv: readonly string[]; +} + +export interface ReplayModel { + /** The cache's name for the model. */ + id: string; + /** What a reader should call it. */ + label: string; + /** The app's embedding index it is (packages/llm/src/embeddings/index-registry.ts); null for the local model. */ + indexKey: string | null; + /** + * Endpoints that serve the model, by name. `direct` is the vendor's own. + * `openrouter` serves the same model at the same list price; it is there + * for a key whose direct quota is too small to record a pool (the free + * tier of Google's endpoint takes 100 texts a minute). + */ + routes?: Readonly>; + /** List price in US dollars per million input tokens, for the estimate a recording prints. */ + usdPerMTok?: number; +} + +const OPENROUTER = "https://openrouter.ai/api/v1"; + +export const REPLAY_MODELS: readonly ReplayModel[] = [ + { + id: LOCAL_MODEL, + label: "nomic-embed-text (local, the benchmark's model)", + indexKey: null, + }, + { + id: "gemini-embedding-001@768", + label: "gemini-embedding-001 at 768 dimensions (index gemini-embedding-768, the one the registry recommends)", + indexKey: "gemini-embedding-768", + routes: { + direct: { + baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai", + model: "gemini-embedding-001", + keyEnv: ["GOOGLE_AI_API_KEY"], + }, + openrouter: { + baseUrl: OPENROUTER, + model: "google/gemini-embedding-001", + keyEnv: ["OPENROUTER_API_KEY"], + }, + }, + usdPerMTok: 0.15, + }, + { + id: "text-embedding-3-large@1536", + label: "text-embedding-3-large at 1536 dimensions (index legacy-openai-1536, the default)", + indexKey: "legacy-openai-1536", + routes: { + direct: { + baseUrl: "https://api.openai.com/v1", + model: "text-embedding-3-large", + keyEnv: ["EMBEDDING_API_KEY", "OPENAI_API_KEY"], + }, + openrouter: { + baseUrl: OPENROUTER, + model: "openai/text-embedding-3-large", + keyEnv: ["OPENROUTER_API_KEY"], + }, + }, + usdPerMTok: 0.13, + }, +]; + +export function replayModel(id: string): ReplayModel { + const model = REPLAY_MODELS.find(m => m.id === id); + if (!model) + throw new Error(`Unknown model "${id}". Known: ${REPLAY_MODELS.map(m => m.id).join(", ")}`); + return model; +} + +/** Reads cached vectors only: a replay never calls a model. */ +export function offlineEmbedder(id: string): ReplayEmbedder { + return cachedEmbedder({ model: replayModel(id).id }); +} + +export interface RecordingEmbedder extends ReplayEmbedder { + /** Tokens as the provider counted them, or the client's estimate where it reports none. */ + readonly spent: { tokens: number; requests: number }; +} + +/** + * Computes what the cache lacks with production's own client and the + * registry's dimensions. Paid: only record.ts builds one, after its checks. + * `cache: false` computes without reading or writing the cache (the check + * that two routes return the same vectors). + */ +export function recordingEmbedder( + id: string, + options: { + route?: string; + env?: Record; + cache?: boolean; + } = {} +): RecordingEmbedder { + const model = replayModel(id); + const route = model.routes?.[options.route ?? "direct"]; + if (!model.indexKey || !route) + throw new Error( + model.routes + ? `${model.id} has no route "${options.route}". Known: ${Object.keys(model.routes).join(", ")}` + : `${model.id} is the local model: ../e4-whom-to-check/record.ts records it` + ); + const index = resolveEmbeddingIndex(model.indexKey); + const env = options.env ?? process.env; + const apiKey = route.keyEnv.map(name => env[name]).find(Boolean); + if (!apiKey) throw new Error(`None of ${route.keyEnv.join(", ")} is set`); + const spent = { tokens: 0, requests: 0 }; + const compute = async (texts: string[]): Promise => { + const result = await generateEmbeddings(texts, { + apiKey, + baseUrl: route.baseUrl, + model: route.model, + dimensions: index.dimension, + concurrency: 2, + }); + spent.tokens += result.totalTokens; + spent.requests += result.batchCount; + return result.embeddings; + }; + if (options.cache === false) + return { + model: model.id, + stats: { cached: 0, computed: 0 }, + spent, + embed: texts => compute(texts.map(t => t.slice(0, 2_000))), + }; + return Object.assign(cachedEmbedder({ model: model.id, compute }), { spent }); +} diff --git a/pipelines/experiments/company-search/production-replay/record.ts b/pipelines/experiments/company-search/production-replay/record.ts new file mode 100644 index 000000000..6bd422ed2 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/record.ts @@ -0,0 +1,86 @@ +/** + * The paid step of the production replay: embeds the benchmark's pools, briefs + * and baseline with one of the app's built-in embedding models and writes the + * vectors to the local cache, so every replay after it is free and offline. + * + * COMPANY_SEARCH_BENCH_MODE=record pnpm exec tsx \ + * experiments/company-search/production-replay/record.ts \ + * --model=gemini-embedding-001@768 --cap-usd=1 [--pools=brreg-food,brreg-drinks] [--via=openrouter] + * + * `--via` picks the endpoint (models.ts): the vendor's own by default. + * + * It sends nothing unless record mode is set and a spend cap is given, prints + * its estimate first and stops when the estimate is over the cap. A text that + * is already cached is never sent again, so a run can be stopped and started + * again. What leaves the machine: company names and their own activity texts + * (no address, phone or email), to the model's provider. + */ +import { BASELINE_TEXT } from "../../../src/distribution/semantic"; +import { allQueryTexts } from "../e4-whom-to-check/briefs"; +import { createRecorder, loadPool, POOL_IDS } from "../e4-whom-to-check/data"; +import type { PoolId } from "../e4-whom-to-check/segments"; +import { defaultMode } from "../lib/recorder"; +import { recordingEmbedder, replayModel } from "./models"; +import { cachedEmbedder, NotCachedError } from "./vectors"; + +const args = new Map( + process.argv.slice(2).map(arg => { + const [key, value] = arg.replace(/^--/, "").split("="); + return [key!, value ?? "true"] as const; + }) +); +const modelId = args.get("model"); +const capUsd = Number(args.get("cap-usd")); +if (!modelId || !Number.isFinite(capUsd) || capUsd <= 0) { + console.error( + "Usage: record.ts --model= --cap-usd= [--pools=a,b] [--via=]" + ); + process.exit(1); +} +if (defaultMode() !== "record") { + console.error("Not in record mode (COMPANY_SEARCH_BENCH_MODE=record): nothing was sent."); + process.exit(1); +} +const model = replayModel(modelId); +const poolIds = (args.get("pools")?.split(",") as PoolId[] | undefined) ?? POOL_IDS; + +const recorder = createRecorder("replay"); +const texts = new Set([BASELINE_TEXT, ...allQueryTexts()]); +for (const id of poolIds) for (const text of (await loadPool(recorder, id)).texts) texts.add(text); + +// What is not cached yet, and what sending it would cost at the list price. +const offline = cachedEmbedder({ model: model.id }); +const missing: string[] = []; +for (const text of texts) { + try { + await offline.embed([text]); + } catch (error) { + if (!(error instanceof NotCachedError)) throw error; + missing.push(text); + } +} +const chars = missing.reduce((sum, text) => sum + Math.min(text.length, 2_000), 0); +// Three characters a token: on the safe side for Norwegian. +const tokens = Math.ceil(chars / 3); +const estimate = (tokens / 1e6) * (model.usdPerMTok ?? 0); +console.log( + `${model.label}: ${texts.size} texts, ${missing.length} not cached (${chars} characters, about ${tokens} tokens, about $${estimate.toFixed(3)} at $${model.usdPerMTok} per million)` +); +if (missing.length === 0) process.exit(0); +if (estimate > capUsd) { + console.error(`Over the cap of $${capUsd}: nothing was sent.`); + process.exit(1); +} +const embedder = recordingEmbedder(model.id, { route: args.get("via") }); +const started = Date.now(); +const CHUNK = 960; +for (let at = 0; at < missing.length; at += CHUNK) { + await embedder.embed(missing.slice(at, at + CHUNK)); + console.log( + ` ${Math.min(missing.length, at + CHUNK)} of ${missing.length} (${Math.round((Date.now() - started) / 1000)} s)` + ); +} +const spentUsd = (embedder.spent.tokens / 1e6) * (model.usdPerMTok ?? 0); +console.log( + `Recorded ${embedder.stats.computed} vectors with ${model.id}: ${embedder.spent.tokens} tokens in ${embedder.spent.requests} requests, about $${spentUsd.toFixed(3)}.` +); diff --git a/pipelines/experiments/company-search/production-replay/run.ts b/pipelines/experiments/company-search/production-replay/run.ts new file mode 100644 index 000000000..04aedfd3b --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/run.ts @@ -0,0 +1,138 @@ +/** + * Replays the benchmark's pools through production's ranking code and writes + * ../results/production-*.json. Offline: recorded pools and cached vectors + * only, never a model or a network call. + * + * pnpm exec tsx experiments/company-search/production-replay/run.ts # the local model + * pnpm exec tsx experiments/company-search/production-replay/run.ts brief --model=gemini-embedding-001@768 + * pnpm exec tsx experiments/company-search/production-replay/run.ts brief --seeds=3 + * + * `brief`: an English brief beside a Norwegian one on the three Norwegian + * pools. `--model` is one of models.ts whose vectors are on this machine + * (record.ts records the paid ones); each model has its own block in the + * results file. A run with fewer than E4's twenty seeds prints its table and + * leaves the file alone. + */ +import { existsSync, readFileSync, writeFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +import { SIMULATION } from "../e4-whom-to-check/config"; +import { stringifyResults } from "../lib/json"; +import { + BRIEF_BUDGETS, + briefTable, + runBriefLanguageReplay, + type BriefSummary, +} from "./brief-language"; +import { offlineEmbedder, REPLAY_MODELS, replayModel } from "./models"; +import { LOCAL_MODEL, recordingsPresent } from "./vectors"; + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const RESULTS = path.resolve(HERE, "..", "results"); +export const BRIEF_RESULTS = path.join(RESULTS, "production-brief-language.json"); + +interface Results { + experiment: string; + question: string; + design: Record; + /** One block per embedding model the pools were replayed with. */ + byEmbedding: Record; +} +export type BriefResults = Results; + +function read(file: string): Results | null { + if (!existsSync(file)) return null; + return JSON.parse(readFileSync(file, "utf8")) as Results; +} +export const readBriefResults = (): BriefResults | null => read(BRIEF_RESULTS); + +const INTERVALS = "95% percentile bootstrap, 2,000 resamples: over pools and then seeds, as in E4"; + +const embeddingModels = (models: Record): Record => + Object.fromEntries(Object.keys(models).map(id => [id, replayModel(id).label])); + +/** A file's blocks with one model's replaced, in the registry's order whichever run wrote last. */ +function merged( + previous: Results | null, + model: string, + summary: Summary +): Record { + const all: Record = { + ...(previous?.byEmbedding ?? {}), + [model]: summary, + }; + return Object.fromEntries(REPLAY_MODELS.filter(m => m.id in all).map(m => [m.id, all[m.id]!])); +} + +function briefDesign(byEmbedding: Record): Record { + return { + code: "src/distribution/semantic.ts (semanticRelevance), as production runs it; companies are checked from the top of that ranking down, as production does", + pools: "E4's three Norwegian register pools: the companies' texts are Norwegian", + briefs: { + english: "the segment as an English-writing seller types it", + norwegian: "E4's Norwegian brief: the same segment as a Norwegian seller would type it", + higher: "per company, the higher of its two relevance scores", + }, + check: "one check reveals one company's hidden label (its register code) and costs 1", + candidates: `a seed's ${SIMULATION.subsample * 100}% draw of the pool, in the order of its relevance to the brief`, + metrics: { + found: `good companies among the first ${BRIEF_BUDGETS.join(", ")} checks of today's fixed ranking`, + zeroScoreRule: + "whole pool: the share of companies, and of good companies, whose relevance is above zero, which is what production keeps before any fit check", + }, + embeddingModels: embeddingModels(byEmbedding), + intervals: INTERVALS, + }; +} + +async function main(): Promise { + const positional = process.argv.slice(2).filter(arg => !arg.startsWith("--")); + const args = new Map( + process.argv + .slice(2) + .filter(arg => arg.startsWith("--")) + .map(arg => { + const [key, value] = arg.replace(/^--/, "").split("="); + return [key!, value ?? "true"] as const; + }) + ); + const which = positional.length > 0 ? positional : ["brief"]; + const model = replayModel(args.get("model") ?? LOCAL_MODEL); + const seedCount = Number(args.get("seeds") ?? SIMULATION.seeds.length); + const seeds = SIMULATION.seeds.slice(0, seedCount); + const full = seedCount === SIMULATION.seeds.length; + if (!recordingsPresent(model.id)) { + console.error( + `The recorded pools or the ${model.id} vectors are not on this machine (COMPANY_SEARCH_BENCH_CACHE). Nothing to replay.` + ); + process.exit(1); + } + const started = Date.now(); + const progress = (line: string): void => + console.log(`[${String(Math.round((Date.now() - started) / 1000)).padStart(4)} s] ${line}`); + + if (which.includes("brief")) { + const summary = await runBriefLanguageReplay({ + embedder: offlineEmbedder(model.id), + seeds, + }); + console.log(`\n${briefTable(model.id, summary)}\n`); + if (full) { + const byEmbedding = merged(readBriefResults(), model.id, summary); + const results: BriefResults = { + experiment: "production-replay: the segment brief in the buyers' language", + question: + "On Norwegian company texts, does a Norwegian brief rank better than an English one with the app's two built-in embedding models?", + design: briefDesign(byEmbedding), + byEmbedding, + }; + writeFileSync(BRIEF_RESULTS, stringifyResults(results)); + progress(`wrote ${path.relative(process.cwd(), BRIEF_RESULTS)}`); + } + } + if (!full) console.log(`${seedCount} seeds: a partial run, results files left as they are.`); +} + +if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) + await main(); diff --git a/pipelines/experiments/company-search/production-replay/vectors.ts b/pipelines/experiments/company-search/production-replay/vectors.ts new file mode 100644 index 000000000..53247d324 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/vectors.ts @@ -0,0 +1,112 @@ +/** + * Embedding vectors for the replays, from the on-disk cache the experiments + * share (../lib/embed.ts writes the same files for the local model). + * + * A replay never calls a model: a text that is not cached is an error unless + * the caller hands in `compute`, which is how a recording run fills the cache + * for a paid model once. The cache sits beside the recorded pools and is never + * committed (see ../.gitignore). + */ +import { createHash } from "node:crypto"; +import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; +import path from "node:path"; + +import { DEFAULT_CACHE_DIR } from "../lib/recorder"; + +export interface ReplayEmbedder { + /** The cache's name for the model, with its dimensions when they are a choice. */ + readonly model: string; + /** One vector per text, in order. */ + embed(texts: readonly string[]): Promise; + /** Texts answered from disk / computed by the model, in this process. */ + readonly stats: { cached: number; computed: number }; +} + +export interface CachedEmbedderOptions { + model: string; + /** Computes vectors for texts the cache lacks; absent, a missing text is an error. */ + compute?: (texts: string[]) => Promise; + /** Texts per `compute` call (default 96). */ + batchSize?: number; + /** Characters kept per text before embedding (default 2,000, as production's companyText). */ + maxChars?: number; + dir?: string; +} + +export class NotCachedError extends Error { + constructor(model: string, missing: number) { + super( + `${missing} text(s) have no cached ${model} vector. A replay never calls a model: record them first.` + ); + this.name = "NotCachedError"; + } +} + +export function embeddingCacheDir(model: string, dir = DEFAULT_CACHE_DIR): string { + return path.join(dir, "embeddings", model.replace(/[^\w.-]/g, "_")); +} + +export function cachedEmbedder(options: CachedEmbedderOptions): ReplayEmbedder { + const { model, compute } = options; + const batchSize = options.batchSize ?? 96; + const maxChars = options.maxChars ?? 2_000; + const dir = embeddingCacheDir(model, options.dir); + const stats = { cached: 0, computed: 0 }; + /** A pool is read once per process, however many seeds replay it. */ + const memory = new Map(); + + const fileFor = (text: string): string => { + const hash = createHash("sha1").update(`${model}\n${text}`).digest("hex"); + return path.join(dir, hash.slice(0, 2), `${hash}.f32`); + }; + const read = (text: string): number[] | null => { + const known = memory.get(text); + if (known) return known; + const file = fileFor(text); + if (!existsSync(file)) return null; + const buffer = readFileSync(file); + const vector = Array.from( + new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4) + ); + memory.set(text, vector); + return vector; + }; + const write = (text: string, vector: readonly number[]): void => { + const file = fileFor(text); + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, Buffer.from(new Float32Array(vector).buffer)); + // What a replay will read back is the single-precision copy. + memory.set(text, Array.from(new Float32Array(vector))); + }; + + return { + model, + stats, + async embed(texts) { + const clipped = texts.map(t => t.slice(0, maxChars)); + const found = clipped.map(read); + const missing = [...new Set(clipped.filter((_, i) => found[i] === null))]; + stats.cached += clipped.length - found.filter(v => v === null).length; + if (missing.length > 0) { + if (!compute) throw new NotCachedError(model, missing.length); + for (let i = 0; i < missing.length; i += batchSize) { + const batch = missing.slice(i, i + batchSize); + const vectors = await compute(batch); + if (vectors.length !== batch.length) + throw new Error(`${model} returned a different number of vectors`); + for (const [j, text] of batch.entries()) write(text, vectors[j]!); + stats.computed += batch.length; + } + } + return clipped.map(text => read(text)!); + }, + }; +} + +/** The local model the benchmark was recorded with. */ +export const LOCAL_MODEL = "nomic-embed-text"; + +/** Whether the recorded pools and this model's vectors are on this machine. */ +export function recordingsPresent(model = LOCAL_MODEL, dir = DEFAULT_CACHE_DIR): boolean { + return existsSync(path.join(dir, "e4")) && existsSync(embeddingCacheDir(model, dir)); +} diff --git a/pipelines/experiments/company-search/results/production-brief-language.json b/pipelines/experiments/company-search/results/production-brief-language.json new file mode 100644 index 000000000..826c5cddc --- /dev/null +++ b/pipelines/experiments/company-search/results/production-brief-language.json @@ -0,0 +1,672 @@ +{ + "experiment": "production-replay: the segment brief in the buyers' language", + "question": "On Norwegian company texts, does a Norwegian brief rank better than an English one with the app's two built-in embedding models?", + "design": { + "code": "src/distribution/semantic.ts (semanticRelevance), as production runs it; companies are checked from the top of that ranking down, as production does", + "pools": "E4's three Norwegian register pools: the companies' texts are Norwegian", + "briefs": { + "english": "the segment as an English-writing seller types it", + "norwegian": "E4's Norwegian brief: the same segment as a Norwegian seller would type it", + "higher": "per company, the higher of its two relevance scores" + }, + "check": "one check reveals one company's hidden label (its register code) and costs 1", + "candidates": "a seed's 80% draw of the pool, in the order of its relevance to the brief", + "metrics": { + "found": "good companies among the first 25, 50, 100, 200 checks of today's fixed ranking", + "zeroScoreRule": "whole pool: the share of companies, and of good companies, whose relevance is above zero, which is what production keeps before any fit check" + }, + "embeddingModels": { + "nomic-embed-text": "nomic-embed-text (local, the benchmark's model)", + "gemini-embedding-001@768": "gemini-embedding-001 at 768 dimensions (index gemini-embedding-768, the one the registry recommends)", + "text-embedding-3-large@1536": "text-embedding-3-large at 1536 dimensions (index legacy-openai-1536, the default)" + }, + "intervals": "95% percentile bootstrap, 2,000 resamples: over pools and then seeds, as in E4" + }, + "byEmbedding": { + "nomic-embed-text": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-coffee-tea", + "pool": "brreg-food", + "candidates": 3484, + "good": 109, + "found": { + "english": { + "found25": 14.4, + "found50": 18.4, + "found100": 29.8, + "found200": 51.85 + }, + "norwegian": { + "found25": 13.15, + "found50": 20.2, + "found100": 28.65, + "found200": 41.95 + }, + "higher": { + "found25": 13.15, + "found50": 20.2, + "found100": 28.65, + "found200": 41.95 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.533, + "goodKept": 0.927 + }, + "norwegian": { + "poolKept": 0.995, + "goodKept": 1 + }, + "higher": { + "poolKept": 0.997, + "goodKept": 1 + } + } + }, + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "candidates": 1138, + "good": 233, + "found": { + "english": { + "found25": 8.65, + "found50": 19.75, + "found100": 30.7, + "found200": 58 + }, + "norwegian": { + "found25": 23.95, + "found50": 42.5, + "found100": 71.6, + "found200": 101.45 + }, + "higher": { + "found25": 23.95, + "found50": 42.5, + "found100": 71.6, + "found200": 101.45 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.389, + "goodKept": 0.597 + }, + "norwegian": { + "poolKept": 0.961, + "goodKept": 0.987 + }, + "higher": { + "poolKept": 0.966, + "goodKept": 0.996 + } + } + }, + { + "segment": "brreg-dental-bergen", + "pool": "brreg-health-bergen", + "candidates": 2954, + "good": 421, + "found": { + "english": { + "found25": 11.55, + "found50": 11.7, + "found100": 14.4, + "found200": 18.4 + }, + "norwegian": { + "found25": 22.85, + "found50": 40.3, + "found100": 75.2, + "found200": 132 + }, + "higher": { + "found25": 22.85, + "found50": 40.3, + "found100": 75.2, + "found200": 132 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.235, + "goodKept": 0.114 + }, + "norwegian": { + "poolKept": 0.961, + "goodKept": 0.995 + }, + "higher": { + "poolKept": 0.966, + "goodKept": 0.998 + } + } + } + ], + "overall": { + "english": { + "found25": { + "mean": 11.53, + "lo": 8.78, + "hi": 14.32 + }, + "found50": { + "mean": 16.62, + "lo": 11.73, + "hi": 19.67 + }, + "found100": { + "mean": 24.97, + "lo": 14.43, + "hi": 30.78 + }, + "found200": { + "mean": 42.75, + "lo": 18.45, + "hi": 57.8 + } + }, + "norwegian": { + "found25": { + "mean": 19.98, + "lo": 13.23, + "hi": 23.92 + }, + "found50": { + "mean": 34.33, + "lo": 20.25, + "hi": 42.42 + }, + "found100": { + "mean": 58.48, + "lo": 28.73, + "hi": 75.08 + }, + "found200": { + "mean": 91.8, + "lo": 42.03, + "hi": 131.73 + } + }, + "higher": { + "found25": { + "mean": 19.98, + "lo": 13.23, + "hi": 23.92 + }, + "found50": { + "mean": 34.33, + "lo": 20.25, + "hi": 42.42 + }, + "found100": { + "mean": 58.48, + "lo": 28.73, + "hi": 75.08 + }, + "found200": { + "mean": 91.8, + "lo": 42.03, + "hi": 131.73 + } + } + }, + "norwegianMinusEnglish": { + "found25": { + "mean": 8.45, + "lo": -1.17, + "hi": 15.17 + }, + "found50": { + "mean": 17.72, + "lo": 1.88, + "hi": 28.53 + }, + "found100": { + "mean": 33.52, + "lo": -1.03, + "hi": 60.7 + }, + "found200": { + "mean": 49.05, + "lo": -9.68, + "hi": 113.45 + } + } + }, + "gemini-embedding-001@768": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-coffee-tea", + "pool": "brreg-food", + "candidates": 3484, + "good": 109, + "found": { + "english": { + "found25": 25, + "found50": 49.8, + "found100": 74.35, + "found200": 79.05 + }, + "norwegian": { + "found25": 25, + "found50": 49.2, + "found100": 70.5, + "found200": 76.6 + }, + "higher": { + "found25": 25, + "found50": 49.2, + "found100": 70.5, + "found200": 76.6 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.068, + "goodKept": 0.908 + }, + "norwegian": { + "poolKept": 0.947, + "goodKept": 0.991 + }, + "higher": { + "poolKept": 0.947, + "goodKept": 0.991 + } + } + }, + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "candidates": 1138, + "good": 233, + "found": { + "english": { + "found25": 25, + "found50": 47.8, + "found100": 92, + "found200": 154.6 + }, + "norwegian": { + "found25": 24.25, + "found50": 48.4, + "found100": 96.5, + "found200": 156.15 + }, + "higher": { + "found25": 24.25, + "found50": 48.4, + "found100": 96.5, + "found200": 156.15 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.439, + "goodKept": 0.936 + }, + "norwegian": { + "poolKept": 0.935, + "goodKept": 0.983 + }, + "higher": { + "poolKept": 0.935, + "goodKept": 0.983 + } + } + }, + { + "segment": "brreg-dental-bergen", + "pool": "brreg-health-bergen", + "candidates": 2954, + "good": 421, + "found": { + "english": { + "found25": 24.15, + "found50": 49.15, + "found100": 98.4, + "found200": 195.8 + }, + "norwegian": { + "found25": 25, + "found50": 49.25, + "found100": 98.35, + "found200": 193.7 + }, + "higher": { + "found25": 25, + "found50": 49.25, + "found100": 98.35, + "found200": 193.7 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.137, + "goodKept": 0.948 + }, + "norwegian": { + "poolKept": 0.868, + "goodKept": 0.981 + }, + "higher": { + "poolKept": 0.868, + "goodKept": 0.981 + } + } + } + ], + "overall": { + "english": { + "found25": { + "mean": 24.72, + "lo": 24.18, + "hi": 25 + }, + "found50": { + "mean": 48.92, + "lo": 47.83, + "hi": 49.78 + }, + "found100": { + "mean": 88.25, + "lo": 74.47, + "hi": 98.35 + }, + "found200": { + "mean": 143.15, + "lo": 79.18, + "hi": 195.73 + } + }, + "norwegian": { + "found25": { + "mean": 24.75, + "lo": 24.27, + "hi": 25 + }, + "found50": { + "mean": 48.95, + "lo": 48.45, + "hi": 49.33 + }, + "found100": { + "mean": 88.45, + "lo": 70.6, + "hi": 98.3 + }, + "found200": { + "mean": 142.15, + "lo": 76.77, + "hi": 193.58 + } + }, + "higher": { + "found25": { + "mean": 24.75, + "lo": 24.27, + "hi": 25 + }, + "found50": { + "mean": 48.95, + "lo": 48.45, + "hi": 49.33 + }, + "found100": { + "mean": 88.45, + "lo": 70.6, + "hi": 98.3 + }, + "found200": { + "mean": 142.15, + "lo": 76.77, + "hi": 193.58 + } + } + }, + "norwegianMinusEnglish": { + "found25": { + "mean": 0.03, + "lo": -0.73, + "hi": 0.82 + }, + "found50": { + "mean": 0.03, + "lo": -0.58, + "hi": 0.57 + }, + "found100": { + "mean": 0.2, + "lo": -3.8, + "hi": 4.4 + }, + "found200": { + "mean": -1, + "lo": -2.52, + "hi": 1.4 + } + } + }, + "text-embedding-3-large@1536": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-coffee-tea", + "pool": "brreg-food", + "candidates": 3484, + "good": 109, + "found": { + "english": { + "found25": 25, + "found50": 42.3, + "found100": 62.45, + "found200": 70.2 + }, + "norwegian": { + "found25": 24.65, + "found50": 41.2, + "found100": 56.95, + "found200": 61.7 + }, + "higher": { + "found25": 24.65, + "found50": 41.2, + "found100": 56.95, + "found200": 61.7 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.099, + "goodKept": 0.853 + }, + "norwegian": { + "poolKept": 0.981, + "goodKept": 0.991 + }, + "higher": { + "poolKept": 0.981, + "goodKept": 0.991 + } + } + }, + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "candidates": 1138, + "good": 233, + "found": { + "english": { + "found25": 21.8, + "found50": 45.45, + "found100": 82.15, + "found200": 141.35 + }, + "norwegian": { + "found25": 21.85, + "found50": 44.05, + "found100": 84.75, + "found200": 139.3 + }, + "higher": { + "found25": 21.85, + "found50": 44.05, + "found100": 84.75, + "found200": 139.3 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.339, + "goodKept": 0.927 + }, + "norwegian": { + "poolKept": 0.944, + "goodKept": 0.996 + }, + "higher": { + "poolKept": 0.944, + "goodKept": 0.996 + } + } + }, + { + "segment": "brreg-dental-bergen", + "pool": "brreg-health-bergen", + "candidates": 2954, + "good": 421, + "found": { + "english": { + "found25": 18.8, + "found50": 39.15, + "found100": 78.95, + "found200": 143 + }, + "norwegian": { + "found25": 17, + "found50": 35.35, + "found100": 68.1, + "found200": 130.55 + }, + "higher": { + "found25": 17, + "found50": 35.35, + "found100": 68.1, + "found200": 130.55 + } + }, + "zeroScoreRule": { + "english": { + "poolKept": 0.578, + "goodKept": 0.936 + }, + "norwegian": { + "poolKept": 0.996, + "goodKept": 1 + }, + "higher": { + "poolKept": 0.996, + "goodKept": 1 + } + } + } + ], + "overall": { + "english": { + "found25": { + "mean": 21.87, + "lo": 18.88, + "hi": 25 + }, + "found50": { + "mean": 42.3, + "lo": 39.22, + "hi": 45.4 + }, + "found100": { + "mean": 74.52, + "lo": 62.58, + "hi": 82 + }, + "found200": { + "mean": 118.18, + "lo": 70.32, + "hi": 142.93 + } + }, + "norwegian": { + "found25": { + "mean": 21.17, + "lo": 17.07, + "hi": 24.62 + }, + "found50": { + "mean": 40.2, + "lo": 35.42, + "hi": 44.02 + }, + "found100": { + "mean": 69.93, + "lo": 57.1, + "hi": 84.6 + }, + "found200": { + "mean": 110.52, + "lo": 61.82, + "hi": 138.9 + } + }, + "higher": { + "found25": { + "mean": 21.17, + "lo": 17.07, + "hi": 24.62 + }, + "found50": { + "mean": 40.2, + "lo": 35.42, + "hi": 44.02 + }, + "found100": { + "mean": 69.93, + "lo": 57.1, + "hi": 84.6 + }, + "found200": { + "mean": 110.52, + "lo": 61.82, + "hi": 138.9 + } + } + }, + "norwegianMinusEnglish": { + "found25": { + "mean": -0.7, + "lo": -1.72, + "hi": 0.07 + }, + "found50": { + "mean": -2.1, + "lo": -3.73, + "hi": -1.02 + }, + "found100": { + "mean": -4.58, + "lo": -10.72, + "hi": 2.42 + }, + "found200": { + "mean": -7.67, + "lo": -12.27, + "hi": -2.12 + } + } + } + } +} From fd33fbaef982919ccb1243202c6bbcbc2de9d8be Mon Sep 17 00:00:00 2001 From: Deodate-Lawson Date: Thu, 26 Nov 2026 18:04:18 -0500 Subject: [PATCH 2/3] Prospects: the shortlist learns from each fit verdict and keeps what it learned The fit check worked down a fixed ranking, 50 companies in its first round, and every verdict was gone when the run ended. Now: - Rounds of ten. After each round the ranking of everyone not checked yet is redone from the verdicts so far, and the highest ranked go next: LinUCB over the candidates' embeddings (src/distribution/learn.ts), driven by the loop in src/distribution/shortlist.ts. Before any verdict the learner predicts the fixed ranking exactly; its first round is close to that order, not equal to it, because a bonus goes to companies unlike the ones already asked about. Companies matched by shared words (no embedder) are checked in the fixed order and rounds as before. - Verdicts are kept, one row per company and segment (distribution_fit_verdicts): the look at the listing, and what research found, which outranks it. The next run's ranking starts from them and from people's own decisions on the segment's deals (qualified, pursued or won is a yes; Not a fit is a no). The fit check's verdicts are kept under the question they answered: what the segment sells, who buys it and as what, what rules a company out, and where, as the run narrowed them. A rewritten or moved segment starts afresh; people's decisions always count. With no fit check to ask, earlier verdicts still order the list. - A fit check that breaks off part-way no longer leaves a shortlist of only the companies it got through, which with rounds of ten could be two. The places it left open go to the next companies down the ranking, unchecked; a company named outside the area that was never read stays out, as with no fit check. The run's warning now says which happened: nothing was checked, part of the list is unchecked, or only the read ones are on it. - The run sheet's Shortlist step has a Fit check row: how many companies were read and turned away, and how many earlier verdicts the ranking started from. A check that broke off shows as failed, with how far it got. English and Chinese. - A failure in any of this does not stop a run or its fit check. When verdicts cannot be read or kept the run learns from its own verdicts alone; a learner that cannot be built, or cannot rank (a stored embedding that is not a number), hands over to the fixed ranking. The log says which. Measured by replaying the benchmark's seven pools through this code (experiments/company-search/production-replay, 20 seeds, 95% intervals): embedding model today learner found in 100 checks nomic-embed-text (local) 59.2 80.7 +21.5 (+11.9 to +32.1) gemini-embedding-001 at 768 69.7 84.5 +14.9 (+5.1 to +25.2) text-embedding-3-large at 1536 67.0 82.5 +15.5 (+6.5 to +23.4) The first 25 checks are level on every model; the gain comes from about the 50th on. A 25-place shortlist fills in about 33 checks instead of 50 to 53, and most of that is the round size: the fixed order asked ten at a time needs 35 to 42. So a default run ends before the learner's lead has opened; the lead is what a longer search gets. Four of the fourteen pool and model pairs on the app's two built-in models are worse, by 0.2 to 1.7 companies in 100 checks. The replay ranks every company of a pool; with a run's relevance-above-zero rule applied first (--zero-score-rule) today's figures do not move and the three gains are +21.3, +15.9 and +16.1. On one pool judged in full by the real fit check (1,422 companies, the fast route of the committed chat configuration) the fit check agrees with the register on 96.8% of the companies, 3 of 200 verdicts changed when asked again, and the learner behaves as it does on the labels: +48.0 yes's in 100 checks where the fixed ranking is poor, +3.4 where it already finds 92. A second run on companies it has never seen, starting from the first run's kept verdicts, gets 9.6 yes's in its first ten checks against 4.4 starting from nothing where the ranking is poor, and 10.0 against 9.0 where it is good. Migration 20261124154024_distribution_fit_verdicts adds the one table; a changeset (minor, @launchstack/pipelines) describes the change for the package's consumers. Co-Authored-By: Claude Fable 5.2 --- .changeset/prospects-shortlist-learns.md | 39 + apps/web/__tests__/prospects/adapter.test.ts | 112 + .../fit-verdicts.integration.test.ts | 498 + .../prospects/server-language.test.ts | 60 + ...261124154024_distribution_fit_verdicts.sql | 21 + .../drizzle/meta/20261124154024_snapshot.json | 23040 ++++++++++++++++ apps/web/drizzle/meta/_journal.json | 7 + apps/web/src/i18n/messages/en/growth.json | 5 + apps/web/src/i18n/messages/zh-CN/growth.json | 5 + apps/web/src/server/prospects/adapter.ts | 36 + docs/manual-testing-guide.md | 19 +- .../experiments/company-search/README.md | 22 +- .../company-search/e4-whom-to-check/README.md | 2 +- .../production-replay/README.md | 102 +- .../production-replay/later-run.ts | 180 + .../production-replay/record-verdicts.ts | 195 + .../company-search/production-replay/run.ts | 146 +- .../production-replay/shortlist-replay.ts | 197 + .../production-replay/shortlist-report.ts | 148 + .../production-replay/shortlist-run.ts | 70 + .../production-replay/shortlist.test.ts | 124 + .../production-replay/verdict-replay.test.ts | 71 + .../production-replay/verdict-replay.ts | 209 + .../production-replay/verdicts.ts | 68 + .../results/production-shortlist.json | 1376 + .../results/production-verdicts.json | 1600 ++ pipelines/src/distribution/db.ts | 175 + pipelines/src/distribution/index.ts | 2 + pipelines/src/distribution/learn.test.ts | 400 + pipelines/src/distribution/learn.ts | 506 + pipelines/src/distribution/run.test.ts | 287 +- pipelines/src/distribution/run.ts | 281 +- pipelines/src/distribution/schema.ts | 61 +- pipelines/src/distribution/semantic.test.ts | 14 + pipelines/src/distribution/semantic.ts | 64 +- pipelines/src/distribution/shortlist.test.ts | 262 + pipelines/src/distribution/shortlist.ts | 188 + pipelines/src/distribution/stages.test.ts | 21 + pipelines/src/distribution/stages.ts | 12 + pipelines/src/distribution/types.ts | 21 + 40 files changed, 30533 insertions(+), 113 deletions(-) create mode 100644 .changeset/prospects-shortlist-learns.md create mode 100644 apps/web/__tests__/prospects/fit-verdicts.integration.test.ts create mode 100644 apps/web/drizzle/20261124154024_distribution_fit_verdicts.sql create mode 100644 apps/web/drizzle/meta/20261124154024_snapshot.json create mode 100644 pipelines/experiments/company-search/production-replay/later-run.ts create mode 100644 pipelines/experiments/company-search/production-replay/record-verdicts.ts create mode 100644 pipelines/experiments/company-search/production-replay/shortlist-replay.ts create mode 100644 pipelines/experiments/company-search/production-replay/shortlist-report.ts create mode 100644 pipelines/experiments/company-search/production-replay/shortlist-run.ts create mode 100644 pipelines/experiments/company-search/production-replay/shortlist.test.ts create mode 100644 pipelines/experiments/company-search/production-replay/verdict-replay.test.ts create mode 100644 pipelines/experiments/company-search/production-replay/verdict-replay.ts create mode 100644 pipelines/experiments/company-search/production-replay/verdicts.ts create mode 100644 pipelines/experiments/company-search/results/production-shortlist.json create mode 100644 pipelines/experiments/company-search/results/production-verdicts.json create mode 100644 pipelines/src/distribution/learn.test.ts create mode 100644 pipelines/src/distribution/learn.ts create mode 100644 pipelines/src/distribution/shortlist.test.ts create mode 100644 pipelines/src/distribution/shortlist.ts diff --git a/.changeset/prospects-shortlist-learns.md b/.changeset/prospects-shortlist-learns.md new file mode 100644 index 000000000..fcd249908 --- /dev/null +++ b/.changeset/prospects-shortlist-learns.md @@ -0,0 +1,39 @@ +--- +"@launchstack/pipelines": minor +--- + +The Prospects fit check learns as it goes, and a run keeps what it learned. + +- The shortlist's fit check asks about ten companies a round, where it asked + about two per open place (fifty in the first round of the default 25-place + shortlist). After each round `fillShortlist` re-ranks everyone not checked + yet from the verdicts so far (`createShortlistLearner`: LinUCB over the + candidates' embeddings) and asks about the highest ranked next. Before any + verdict the learner's prediction is the fixed relevance ranking; from the + first round on it adds a bonus for companies unlike the ones already asked + about, so the first round is close to the fixed order, not equal to it. + Companies matched by shared words (no embedding model) are checked in the + fixed order and rounds as before. +- Verdicts are kept in the new table `distribution_fit_verdicts`, one row per + company and segment (`saveFitVerdicts`, `listFitExamples`). The next run's + ranking starts from them and from the stage people moved the segment's + deals to (`fitDecision`). The fit check's verdicts are kept under the + question they answered (`segmentKey`: offering, categories, constraints, + buyer kinds and area, as the run narrowed them), so a segment that was + rewritten or moved starts afresh. People's decisions always count. +- A fit check that breaks off part-way no longer leaves a shortlist of only + the companies it got through: the places it left open go to the next + companies down the ranking, unchecked. A company named outside the + segment's area that the check never read stays out, as it does with no fit + check at all. The run's warning says which of the three happened: nothing + was checked, part of the list is unchecked, or the list holds only the + companies that were read. +- `RunSummary.fitCheck` (optional) says how many companies the fit check read, + in how many rounds, how many it turned away, how many earlier verdicts the + ranking started from and whether it broke off (`incomplete`). `Relevance` + gains optional `vectors` and `measure`. + +The table comes with the app's migration +`20261124154024_distribution_fit_verdicts`. A failure to read or keep verdicts +never stops a run: it learns from its own verdicts alone. When the learner +cannot be built, or cannot rank, the fixed ranking takes over. diff --git a/apps/web/__tests__/prospects/adapter.test.ts b/apps/web/__tests__/prospects/adapter.test.ts index 676d291af..223589e47 100644 --- a/apps/web/__tests__/prospects/adapter.test.ts +++ b/apps/web/__tests__/prospects/adapter.test.ts @@ -316,6 +316,118 @@ describe("runs", () => { expect(sources.children!.map(c => c.status)).toEqual(["done", "skipped", "done"]); }); + /** A completed run's summary, before any fit check is counted in it. */ + const summary = { + sources: [{ source: "web" as const, queries: 4, results: 60, status: "ok" as const }], + mentions: 60, + resolved: 51, + excluded: 0, + shortlisted: 25, + enriched: 25, + gateRejections: 0, + budgetExhausted: 0, + screened: 0, + flagged: 0, + published: 0, + degraded: false, + warnings: [], + tokens: { input: 0, output: 0, total: 0 }, + }; + + it("says under the shortlist what the fit check read and what the ranking already knew", () => { + const shortlist = (fitCheck?: { + checked: number; + rounds: number; + rejected: number; + learning: boolean; + startedFrom: number; + incomplete?: boolean; + }) => + toRunDto( + run({ + status: "completed", + summary: { ...summary, ...(fitCheck ? { fitCheck } : {}) }, + }) + ).steps.find(s => s.id === "shortlist")!; + + // A run without a fit check, and every run from before it was counted: no row. + expect(shortlist().children).toBeUndefined(); + + const first = shortlist({ + checked: 34, + rounds: 4, + rejected: 9, + learning: true, + startedFrom: 0, + }).children!; + expect(first.map(c => [c.id, c.label, c.detail, c.right, c.status])).toEqual([ + ["fit-check", "Fit check", "34 read, 9 turned away", null, "done"], + ]); + expect(first[0]!.detailCopy).toEqual({ + key: "growth.server.runs.fitRead", + values: { checked: "34", rejected: "9" }, + }); + + const later = shortlist({ + checked: 30, + rounds: 3, + rejected: 5, + learning: true, + startedFrom: 35, + }).children![0]!; + expect(later.right).toBe("35 earlier verdicts"); + // A number, so the catalogue can say "1 earlier verdict". + expect(later.rightCopy).toEqual({ + key: "growth.server.runs.fitStartedFrom", + values: { count: 35 }, + }); + const one = shortlist({ + checked: 30, + rounds: 3, + rejected: 5, + learning: true, + startedFrom: 1, + }).children![0]!; + expect(one.right).toBe("1 earlier verdict"); + }); + + it("shows a fit check that broke off as failed, with what it got through", () => { + const row = (checked: number, rejected: number) => + toRunDto( + run({ + status: "completed", + summary: { + ...summary, + fitCheck: { + checked, + rounds: checked > 0 ? 1 : 0, + rejected, + learning: true, + startedFrom: 0, + incomplete: true, + }, + }, + }) + ).steps.find(s => s.id === "shortlist")!.children![0]!; + + // The model failed on its second round: ten were read. + const stopped = row(10, 8); + expect([stopped.label, stopped.detail, stopped.status]).toEqual([ + "Fit check", + "stopped after 10 read", + "failed", + ]); + expect(stopped.detailCopy).toEqual({ + key: "growth.server.runs.fitStopped", + values: { checked: "10" }, + }); + + // It failed at once: no tick over "0 read, 0 turned away". + const never = row(0, 0); + expect([never.detail, never.status]).toEqual(["could not run", "failed"]); + expect(never.detailCopy).toEqual({ key: "growth.server.runs.fitNotRun" }); + }); + it("lists every source, lookalikes included, before a run has a summary", () => { const dto = toRunDto( run({ status: "gathering", options: { maxCandidates: 25, mode: "live" } }) diff --git a/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts b/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts new file mode 100644 index 000000000..a80bf962b --- /dev/null +++ b/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts @@ -0,0 +1,498 @@ +/** + * What is known about who fits a segment is kept between runs, against a real + * database: the fit check's verdicts (one row per company, research outranks + * a later look at the listing), people's own decisions read from the stage of + * the deal, a second run of a segment that starts from what the first one + * learned, and a segment whose area moved, which starts the fit check's + * verdicts afresh. Gated like the other integration suites. + */ +import { eq } from "drizzle-orm"; + +import { configureDatabase } from "@launchstack/store/client"; +import { company } from "@launchstack/store/schema"; +import { + enrichCandidate, + prepareRun, + segmentKey, + type DistributionPorts, +} from "@launchstack/pipelines/distribution"; +import { + createProgram, + createRun, + importPartners, + listFitExamples, + listPartners, + saveFitVerdicts, + transitionStage, + updateProgram, +} from "@launchstack/pipelines/distribution/db"; +import { distributionFitVerdicts } from "@launchstack/pipelines/distribution/schema"; +import type { CompanyHit } from "@launchstack/tools/web-research"; + +import { createFounderWeeklyReviewTestDatabase } from "../founderWeeklyReview/testDb"; + +jest.mock("~/env", () => ({ env: { server: {}, client: {} } })); +jest.mock("@launchstack/tools/company-context", () => ({ + getCompanyIdentity: async () => ({ + data: { + name: "Seller BV", + industry: "Logistics software", + description: "", + categories: [], + }, + }), + buildCompanyKnowledgeContext: async () => "", + formatCompanyIdentity: () => "Company: Seller BV.", +})); + +const describeDb = + process.env.LAUNCHSTACK_TEST_DATABASE_URL || process.env.DATABASE_URL + ? describe + : describe.skip; + +/** + * A deterministic stand-in for an embedding model, as the pipeline's own tests + * use (its semantic.fixture): each word is hashed into one of 512 dimensions, + * so texts that share words point the same way. + */ +const STOP = new Set(["a", "an", "and", "the", "of", "for", "in", "to", "that", "this", "would"]); +const fakeEmbed: NonNullable = async texts => + texts.map(text => { + const vector = new Array(512).fill(0); + for (const raw of text.toLowerCase().split(/[^\p{L}\p{N}]+/u)) { + if (raw.length < 2 || STOP.has(raw)) continue; + const word = raw.replace(/(ies|es|s)$/, ""); + let hash = 2166136261; + for (let i = 0; i < word.length; i++) { + hash ^= word.charCodeAt(i); + hash = Math.imul(hash, 16777619); + } + vector[Math.abs(hash) % 512]! += 1; + } + // Any two business descriptions share a little, as with a real model. + vector[0]! += 1; + return vector; + }); + +// Two kinds of company. More of the brief's own words sit in the agencies' +// listings, so the fixed ranking puts every agency first; only the warehouse +// operators would buy picking robots. +const AGENCY = + "Picking robots and fulfilment warehouses: software consultancy and marketing agency for webshops."; +const OPERATOR = "Fulfilment warehouses operator: picking, storage and shipping for webshops."; +const isOperator = (name: string): boolean => name.includes("Operator"); + +function pool(tag: string, each = 30): CompanyHit[] { + const hit = (domain: string, title: string, description: string): CompanyHit => ({ + title, + url: `https://${domain}/`, + domain, + description, + }); + return [ + ...Array.from({ length: each }, (_, i) => + hit(`${tag}-agency-${i}.example`, `${tag} Agency ${i}`, AGENCY) + ), + ...Array.from({ length: each }, (_, i) => + hit(`${tag}-operator-${i}.example`, `${tag} Operator ${i}`, OPERATOR) + ), + ]; +} + +function ports(companies: CompanyHit[], rounds: string[][]): DistributionPorts { + return { + model: { respond: jest.fn() } as unknown as DistributionPorts["model"], + fetchPage: jest.fn(), + searchWeb: async () => { + throw new Error("discovery must use company search when it is configured"); + }, + searchCompanies: async query => (query.startsWith("Companies similar to") ? [] : companies), + describeCompanies: async () => [], + searchPlaces: null, + tradeData: null, + compliance: null, + publishDossier: null, + debitCredits: null, + writeRationale: null, + creditsPerCandidate: 0, + plan: async () => ({ + plan: { + adjacentBrands: [], + strategy: "", + queries: [ + { + kind: "web", + territory: { country: "NL" }, + partnerKind: "distributor", + query: "fulfilment warehouses Netherlands", + label: "directory", + rationale: "r", + }, + ], + }, + playbookHash: "test", + }), + embed: fakeEmbed, + judgeFit: async ({ candidates }) => { + rounds.push(candidates.map(c => c.name)); + return new Map( + candidates.map(c => [ + c.id, + isOperator(c.name) + ? { fit: true, reason: "Runs a warehouse." } + : { fit: false, reason: "An agency." }, + ]) + ); + }, + }; +} + +describeDb("fit verdicts between runs", () => { + jest.setTimeout(120_000); + + let testDb: Awaited>; + let companyId: bigint; + + const newProgram = (name: string) => + createProgram({ + companyId, + userId: "u1", + input: { + name, + offering: "Picking robots for fulfilment warehouses", + categories: ["fulfilment"], + hsCodes: [], + targetTerritories: [{ country: "NL" }], + partnerKinds: ["distributor"], + constraints: null, + knownPartnerDomains: [], + customerDomains: [], + }, + }); + + beforeAll(async () => { + testDb = await createFounderWeeklyReviewTestDatabase(); + configureDatabase(testDb.db); + const [row] = await testDb.db + .insert(company) + .values({ name: "Seller BV", numberOfEmployees: "5" }) + .returning(); + companyId = BigInt(row!.id); + }, 120_000); + + afterAll(async () => { + await testDb?.close(); + }); + + it("keeps one verdict per company, and research outranks a later look at the listing", async () => { + const program = await newProgram("Verdict rows"); + const key = segmentKey(program); + const verdict = (name: string, fit: boolean) => ({ + resolveKey: `d:${name}.example`, + name, + text: `${name}. ${fit ? OPERATOR : AGENCY}`, + fit, + reason: fit ? "Runs a warehouse." : "An agency.", + }); + const save = ( + basis: "listing" | "research", + segment: string, + ...verdicts: ReturnType[] + ) => + saveFitVerdicts({ + companyId, + programId: program.id, + runId: null, + basis, + segmentKey: segment, + verdicts, + }); + const examples = async (segment = key) => + Object.fromEntries( + ( + await listFitExamples({ companyId, programId: program.id, segmentKey: segment }) + ).map(e => [e.resolveKey, `${e.source}:${e.good}`]) + ); + + await save("listing", key, verdict("a", true), verdict("b", false), verdict("c", true)); + expect(await examples()).toEqual({ + "d:a.example": "listing:true", + "d:b.example": "listing:false", + "d:c.example": "listing:true", + }); + + // Research rules one of them out; a later run's look at the same listing does not undo that. + await save("research", key, verdict("a", false)); + await save("listing", key, verdict("a", true), verdict("b", true)); + expect(await examples()).toEqual({ + "d:a.example": "research:false", + "d:b.example": "listing:true", + "d:c.example": "listing:true", + }); + const rows = await testDb.db + .select() + .from(distributionFitVerdicts) + .where(eq(distributionFitVerdicts.programId, program.id)); + expect(rows).toHaveLength(3); + + // The segment is rewritten: verdicts on the old wording are not what a run starts from, + // and a verdict under the new wording replaces even a research one. + const rewritten = segmentKey({ + ...program, + offering: "Shelving for fulfilment warehouses", + }); + expect(rewritten).not.toBe(key); + expect(await examples(rewritten)).toEqual({}); + await save("listing", rewritten, verdict("a", true)); + expect(await examples(rewritten)).toEqual({ "d:a.example": "listing:true" }); + expect(await examples()).toEqual({ + "d:b.example": "listing:true", + "d:c.example": "listing:true", + }); + }); + + it("starts the second run of a segment from the first run's verdicts and from people's decisions", async () => { + const program = await newProgram("Two runs"); + const key = segmentKey(program); + const start = async (companies: CompanyHit[]) => { + const run = await createRun({ + companyId, + programId: program.id, + userId: "u1", + options: { maxCandidates: 25, mode: "live" }, + }); + const rounds: string[][] = []; + const prepared = await prepareRun( + { runId: run.id, companyId, programId: program.id }, + ports(companies, rounds) + ); + return { run, rounds, prepared }; + }; + + // Run 1 knows nothing: it learns what fits from its own fit checks. + const first = await start(pool("First")); + expect(first.prepared.fitCheck).toMatchObject({ learning: true, startedFrom: 0 }); + const firstAsked = first.rounds.flat(); + const stored = await testDb.db + .select() + .from(distributionFitVerdicts) + .where(eq(distributionFitVerdicts.programId, program.id)); + expect(stored).toHaveLength(firstAsked.length); + expect(stored.every(row => row.fit === isOperator(row.name))).toBe(true); + expect(stored.every(row => row.basis === "listing" && row.runId === first.run.id)).toBe( + true + ); + expect(stored.every(row => row.segmentKey === key)).toBe(true); + + // A person's decisions: one shortlisted operator is not a fit after all, one is + // qualified, and a customer won elsewhere is imported. + const leads = await listPartners(companyId, { programId: program.id }); + expect(leads.length).toBeGreaterThanOrEqual(25); + const [notAFit, qualified] = leads; + await transitionStage({ + companyId, + relationshipId: notAFit!.relationship.id, + to: "lost", + actorUserId: "u1", + }); + await transitionStage({ + companyId, + relationshipId: qualified!.relationship.id, + to: "qualified", + actorUserId: "u1", + }); + await importPartners({ + companyId, + programId: program.id, + userId: "u1", + rows: [ + { + name: "Won Operator", + domain: "won-operator.example", + kind: "distributor", + stage: "won", + }, + ], + }); + const examples = await listFitExamples({ + companyId, + programId: program.id, + segmentKey: key, + }); + const by = new Map(examples.map(e => [e.resolveKey, e])); + expect(by.get(notAFit!.org.resolveKey)).toMatchObject({ source: "person", good: false }); + expect(by.get(qualified!.org.resolveKey)).toMatchObject({ source: "person", good: true }); + expect(by.get("d:won-operator.example")).toMatchObject({ source: "person", good: true }); + // One verdict per company: the person's replaces the fit check's. + expect(examples).toHaveLength(firstAsked.length + 1); + + // Run 2 meets sixty companies it has never seen, and already knows which kind fits. + const second = await start(pool("Second")); + expect(second.prepared.fitCheck).toMatchObject({ + learning: true, + startedFrom: firstAsked.length + 1, + }); + const agencies = (asked: string[]) => asked.filter(name => !isOperator(name)).length; + expect(agencies(second.rounds.flat())).toBeLessThan(agencies(firstAsked)); + expect(second.rounds[0]!.filter(isOperator).length).toBeGreaterThanOrEqual(8); + expect(second.prepared.fitCheck!.checked).toBeLessThanOrEqual( + first.prepared.fitCheck!.checked + ); + expect(second.prepared.candidateRelationshipIds).toHaveLength(25); + }); + + it("keeps what research found about a company over the look at its listing", async () => { + const program = await newProgram("Researched"); + const run = await createRun({ + companyId, + programId: program.id, + userId: "u1", + options: { maxCandidates: 25, mode: "live" }, + }); + const ctx = { runId: run.id, companyId, programId: program.id }; + const prepared = await prepareRun(ctx, ports(pool("Researched"), [])); + const key = segmentKey(program, run.options); + + // The first shortlisted company: the listing said it fits. + const relationshipId = prepared.candidateRelationshipIds[0]!; + const partner = (await listPartners(companyId, { programId: program.id })).find( + item => item.relationship.id === relationshipId + )!; + const rowOf = async () => { + const rows = await testDb.db + .select() + .from(distributionFitVerdicts) + .where(eq(distributionFitVerdicts.programId, program.id)); + return rows.find(row => row.resolveKey === partner.org.resolveKey)!; + }; + expect(await rowOf()).toMatchObject({ basis: "listing", fit: true, segmentKey: key }); + + // Research finds nothing to cite; the fit check on what it found says no. + const asked: string[] = []; + await enrichCandidate( + ctx, + { + ...ports([], []), + profile: async () => ({ + outcome: { status: "gate_failed", dossier: null, errors: [] }, + evidence: [], + fetchedUrls: [], + turns: 0, + usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 }, + playbookHash: "test", + promptVersion: "test", + }), + judgeFit: async ({ candidates }) => { + asked.push(...candidates.map(c => c.name)); + return new Map( + candidates.map(c => [c.id, { fit: false, reason: "Closed last year." }]) + ); + }, + }, + { relationshipId, profile: prepared.profile } + ); + expect(asked).toEqual([partner.org.name]); + expect(await rowOf()).toMatchObject({ + basis: "research", + fit: false, + reason: "Closed last year.", + segmentKey: key, + runId: run.id, + }); + + // The next run reads the listing again and likes it; research still stands. + const next = await createRun({ + companyId, + programId: program.id, + userId: "u1", + options: { maxCandidates: 25, mode: "live" }, + }); + await saveFitVerdicts({ + companyId, + programId: program.id, + runId: next.id, + basis: "listing", + segmentKey: key, + verdicts: [ + { + resolveKey: partner.org.resolveKey, + name: partner.org.name, + text: `${partner.org.name}. ${OPERATOR}`, + fit: true, + reason: "Runs a warehouse.", + }, + ], + }); + expect(await rowOf()).toMatchObject({ basis: "research", fit: false, runId: run.id }); + const known = await listFitExamples({ companyId, programId: program.id, segmentKey: key }); + expect(known.find(e => e.resolveKey === partner.org.resolveKey)).toMatchObject({ + source: "research", + good: false, + }); + }); + + it("starts the fit check's verdicts afresh when the area moves, and still counts people's decisions", async () => { + const program = await newProgram("Moved area"); + const start = async (companies: CompanyHit[]) => { + const run = await createRun({ + companyId, + programId: program.id, + userId: "u1", + options: { maxCandidates: 25, mode: "live" }, + }); + const rounds: string[][] = []; + const prepared = await prepareRun( + { runId: run.id, companyId, programId: program.id }, + ports(companies, rounds) + ); + return { rounds, prepared }; + }; + const keysStored = async () => { + const rows = await testDb.db + .select() + .from(distributionFitVerdicts) + .where(eq(distributionFitVerdicts.programId, program.id)); + const counts = new Map(); + for (const row of rows) + counts.set(row.segmentKey, (counts.get(row.segmentKey) ?? 0) + 1); + return counts; + }; + + // Run 1, in the Netherlands; then a person turns one of its companies away. + const first = await start(pool("First")); + const dutch = segmentKey(program); + const firstAsked = first.rounds.flat().length; + expect(await keysStored()).toEqual(new Map([[dutch, firstAsked]])); + const [notAFit] = await listPartners(companyId, { programId: program.id }); + await transitionStage({ + companyId, + relationshipId: notAFit!.relationship.id, + to: "lost", + actorUserId: "u1", + }); + + // The segment moves to Belgium: the fit check was asked "in the Netherlands?" before. + const moved = await updateProgram(program.id, companyId, { + targetTerritories: [{ country: "BE" }], + }); + const belgian = segmentKey(moved!); + expect(belgian).not.toBe(dutch); + const known = await listFitExamples({ + companyId, + programId: program.id, + segmentKey: belgian, + }); + // None of run 1's verdicts; the person's own decision still counts. + expect(known.map(e => [e.resolveKey, e.source, e.good])).toEqual([ + [notAFit!.org.resolveKey, "person", false], + ]); + + // Run 2 starts from that one decision and keeps its verdicts under the new question. + const second = await start(pool("Second")); + expect(second.prepared.fitCheck).toMatchObject({ learning: true, startedFrom: 1 }); + expect(second.rounds[0]).toHaveLength(10); + const stored = await keysStored(); + expect(stored.get(belgian)).toBe(second.rounds.flat().length); + expect(stored.get(dutch)).toBe(firstAsked); + }); +}); diff --git a/apps/web/__tests__/prospects/server-language.test.ts b/apps/web/__tests__/prospects/server-language.test.ts index 9dd9b23ee..d8c8300d8 100644 --- a/apps/web/__tests__/prospects/server-language.test.ts +++ b/apps/web/__tests__/prospects/server-language.test.ts @@ -129,10 +129,34 @@ const run = (over: Partial): RunRecord => ({ ...over, }); +/** A completed run whose shortlist went through the fit check. */ +const fitChecked = ( + startedFrom: number, + over: { checked?: number; incomplete?: boolean } = {} +): RunRecord => + run({ + summary: { + ...run({}).summary!, + fitCheck: { + checked: 34, + rounds: 4, + rejected: 9, + learning: true, + startedFrom, + ...over, + }, + }, + }); + describe("adapter copies say their English field exactly", () => { it("for a run's steps, figures and caps", () => { for (const dto of [ toRunDto(run({})), + toRunDto(fitChecked(0)), + toRunDto(fitChecked(35)), + toRunDto(fitChecked(1)), + toRunDto(fitChecked(0, { checked: 10, incomplete: true })), + toRunDto(fitChecked(2, { checked: 0, incomplete: true })), toRunDto(run({ status: "enriching", summary: null }), { profiled: 1, shortlisted: 3, @@ -299,6 +323,42 @@ describe("in Chinese", () => { expect(sourceDetailCopy("Exa returned 500")).toBeNull(); }); + it("words the fit check under the shortlist", () => { + const row = (startedFrom: number) => + toRunDto(fitChecked(startedFrom)).steps.find(s => s.id === "shortlist")!.children![0]!; + expect(zh(row(0).labelCopy)).toBe("匹配度检查"); + expect(zh(row(0).detailCopy)).toBe("已读 34 家,排除 9 家"); + expect(row(0).rightCopy).toBeNull(); + expect(zh(row(35).rightCopy)).toBe("此前 35 条判断"); + // English counts one verdict as one. + expect(en(row(35).rightCopy)).toBe("35 earlier verdicts"); + expect(en(row(1).rightCopy)).toBe("1 earlier verdict"); + expect(zh(row(1).rightCopy)).toBe("此前 1 条判断"); + }); + + it("words a fit check that broke off", () => { + const row = (checked: number) => + toRunDto( + run({ + summary: { + ...run({}).summary!, + fitCheck: { + checked, + rounds: checked > 0 ? 1 : 0, + rejected: 0, + learning: true, + startedFrom: 0, + incomplete: true, + }, + }, + }) + ).steps.find(s => s.id === "shortlist")!.children![0]!; + expect(en(row(10).detailCopy)).toBe("stopped after 10 read"); + expect(zh(row(10).detailCopy)).toBe("已读 10 家后中断"); + expect(en(row(0).detailCopy)).toBe("could not run"); + expect(zh(row(0).detailCopy)).toBe("未能运行"); + }); + it("words the lookalike source and its details", () => { const dto = toRunDto( run({ diff --git a/apps/web/drizzle/20261124154024_distribution_fit_verdicts.sql b/apps/web/drizzle/20261124154024_distribution_fit_verdicts.sql new file mode 100644 index 000000000..559149491 --- /dev/null +++ b/apps/web/drizzle/20261124154024_distribution_fit_verdicts.sql @@ -0,0 +1,21 @@ +CREATE TABLE "pdr_ai_v2_distribution_fit_verdicts" ( + "id" bigserial PRIMARY KEY NOT NULL, + "company_id" bigint NOT NULL, + "program_id" varchar(256) NOT NULL, + "resolve_key" varchar(512) NOT NULL, + "name" varchar(512) NOT NULL, + "text" text NOT NULL, + "fit" boolean NOT NULL, + "reason" text, + "basis" varchar(16) NOT NULL, + "segment_key" varchar(64) NOT NULL, + "run_id" varchar(256), + "judged_at" timestamp with time zone DEFAULT CURRENT_TIMESTAMP NOT NULL +); +--> statement-breakpoint +ALTER TABLE "pdr_ai_v2_distribution_fit_verdicts" ADD CONSTRAINT "pdr_ai_v2_distribution_fit_verdicts_company_id_pdr_ai_v2_company_id_fk" FOREIGN KEY ("company_id") REFERENCES "public"."pdr_ai_v2_company"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pdr_ai_v2_distribution_fit_verdicts" ADD CONSTRAINT "pdr_ai_v2_distribution_fit_verdicts_program_id_pdr_ai_v2_distribution_programs_id_fk" FOREIGN KEY ("program_id") REFERENCES "public"."pdr_ai_v2_distribution_programs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "pdr_ai_v2_distribution_fit_verdicts" ADD CONSTRAINT "pdr_ai_v2_distribution_fit_verdicts_run_id_pdr_ai_v2_distribution_runs_id_fk" FOREIGN KEY ("run_id") REFERENCES "public"."pdr_ai_v2_distribution_runs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "distribution_fit_verdicts_program_org_unique" ON "pdr_ai_v2_distribution_fit_verdicts" USING btree ("company_id","program_id","resolve_key");--> statement-breakpoint +CREATE INDEX "distribution_fit_verdicts_company_idx" ON "pdr_ai_v2_distribution_fit_verdicts" USING btree ("company_id");--> statement-breakpoint +CREATE INDEX "distribution_fit_verdicts_program_idx" ON "pdr_ai_v2_distribution_fit_verdicts" USING btree ("program_id","judged_at"); \ No newline at end of file diff --git a/apps/web/drizzle/meta/20261124154024_snapshot.json b/apps/web/drizzle/meta/20261124154024_snapshot.json new file mode 100644 index 000000000..ff70d1c82 --- /dev/null +++ b/apps/web/drizzle/meta/20261124154024_snapshot.json @@ -0,0 +1,23040 @@ +{ + "id": "b700b900-dcfe-4ce0-b7b2-fc59bc2d24d3", + "prevId": "a1648554-587f-4d47-b0fd-900a3b30ca72", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.pdr_ai_v2_document_grants": { + "name": "pdr_ai_v2_document_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "principal_type": { + "name": "principal_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "principal_id": { + "name": "principal_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "granted_by": { + "name": "granted_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "document_grants_document_principal_unique": { + "name": "document_grants_document_principal_unique", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_grants_company_id_idx": { + "name": "document_grants_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_grants_principal_idx": { + "name": "document_grants_principal_idx", + "columns": [ + { + "expression": "principal_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_grants_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_grants_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_grants", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_grants_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_document_grants_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_document_grants", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_public_links": { + "name": "pdr_ai_v2_document_public_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "allow_download": { + "name": "allow_download", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_by": { + "name": "revoked_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "document_public_links_token_unique": { + "name": "document_public_links_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_public_links_live_document_unique": { + "name": "document_public_links_live_document_unique", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "revoked_at is null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_public_links_company_id_idx": { + "name": "document_public_links_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_public_links_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_public_links_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_public_links", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_public_links_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_document_public_links_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_document_public_links", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_settings": { + "name": "pdr_ai_v2_document_settings", + "schema": "", + "columns": { + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "restricted": { + "name": "restricted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "updated_by": { + "name": "updated_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "document_settings_company_id_idx": { + "name": "document_settings_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_settings_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_document_settings_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_document_settings", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_settings_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_settings_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_settings", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_folder_grants": { + "name": "pdr_ai_v2_folder_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "category_id": { + "name": "category_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "principal_type": { + "name": "principal_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "principal_id": { + "name": "principal_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "granted_by": { + "name": "granted_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "folder_grants_category_principal_unique": { + "name": "folder_grants_category_principal_unique", + "columns": [ + { + "expression": "category_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_grants_company_id_idx": { + "name": "folder_grants_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "folder_grants_principal_idx": { + "name": "folder_grants_principal_idx", + "columns": [ + { + "expression": "principal_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_folder_grants_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_folder_grants_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_folder_grants", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_folder_grants_category_id_pdr_ai_v2_category_id_fk": { + "name": "pdr_ai_v2_folder_grants_category_id_pdr_ai_v2_category_id_fk", + "tableFrom": "pdr_ai_v2_folder_grants", + "tableTo": "pdr_ai_v2_category", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_folder_settings": { + "name": "pdr_ai_v2_folder_settings", + "schema": "", + "columns": { + "category_id": { + "name": "category_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'restricted'" + }, + "updated_by": { + "name": "updated_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "folder_settings_company_id_idx": { + "name": "folder_settings_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_folder_settings_category_id_pdr_ai_v2_category_id_fk": { + "name": "pdr_ai_v2_folder_settings_category_id_pdr_ai_v2_category_id_fk", + "tableFrom": "pdr_ai_v2_folder_settings", + "tableTo": "pdr_ai_v2_category", + "columnsFrom": [ + "category_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_folder_settings_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_folder_settings_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_folder_settings", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_activity": { + "name": "pdr_ai_v2_workspace_activity", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "verb": { + "name": "verb", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "target_label": { + "name": "target_label", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "target_path": { + "name": "target_path", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "detail": { + "name": "detail", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "workspace_activity_company_created_idx": { + "name": "workspace_activity_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_activity_company_actor_idx": { + "name": "workspace_activity_company_actor_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "actor_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_activity_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_activity_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_activity", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_audit_events": { + "name": "pdr_ai_v2_workspace_audit_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "action": { + "name": "action", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "detail": { + "name": "detail", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "workspace_audit_events_company_created_idx": { + "name": "workspace_audit_events_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_audit_events_company_action_idx": { + "name": "workspace_audit_events_company_action_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "action", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_audit_events_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_audit_events_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_audit_events", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_group_members": { + "name": "pdr_ai_v2_workspace_group_members", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "added_by": { + "name": "added_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "workspace_group_members_group_user_unique": { + "name": "workspace_group_members_group_user_unique", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_group_members_user_id_idx": { + "name": "workspace_group_members_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_group_members_group_id_pdr_ai_v2_workspace_groups_id_fk": { + "name": "pdr_ai_v2_workspace_group_members_group_id_pdr_ai_v2_workspace_groups_id_fk", + "tableFrom": "pdr_ai_v2_workspace_group_members", + "tableTo": "pdr_ai_v2_workspace_groups", + "columnsFrom": [ + "group_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_workspace_group_members_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_workspace_group_members_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_workspace_group_members", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_groups": { + "name": "pdr_ai_v2_workspace_groups", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(120)", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_groups_company_slug_unique": { + "name": "workspace_groups_company_slug_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_groups_company_id_idx": { + "name": "workspace_groups_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_groups_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_groups_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_groups", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_invitations": { + "name": "pdr_ai_v2_workspace_invitations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "group_ids": { + "name": "group_ids", + "type": "bigint[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::bigint[]" + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "invited_by": { + "name": "invited_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "accepted_at": { + "name": "accepted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "accepted_by_user_id": { + "name": "accepted_by_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "declined_at": { + "name": "declined_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_invitations_token_hash_unique": { + "name": "workspace_invitations_token_hash_unique", + "columns": [ + { + "expression": "token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_invitations_company_id_idx": { + "name": "workspace_invitations_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_invitations_email_idx": { + "name": "workspace_invitations_email_idx", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_invitations_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_invitations_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_invitations", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_notifications": { + "name": "pdr_ai_v2_workspace_notifications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "recipient_user_id": { + "name": "recipient_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "target_id": { + "name": "target_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "target_label": { + "name": "target_label", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "detail": { + "name": "detail", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_notifications_recipient_created_idx": { + "name": "workspace_notifications_recipient_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipient_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_notifications_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_notifications_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_notifications", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_roles": { + "name": "pdr_ai_v2_workspace_roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(120)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "permissions": { + "name": "permissions", + "type": "text[]", + "primaryKey": false, + "notNull": true, + "default": "'{}'::text[]" + }, + "created_by": { + "name": "created_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_roles_company_slug_unique": { + "name": "workspace_roles_company_slug_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_roles_company_id_idx": { + "name": "workspace_roles_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_roles_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_roles_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_roles", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_settings": { + "name": "pdr_ai_v2_workspace_settings", + "schema": "", + "columns": { + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "join_policy": { + "name": "join_policy", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'approval'" + }, + "audit_retention_days": { + "name": "audit_retention_days", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_workspace_settings_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_settings_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_settings", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_chat": { + "name": "pdr_ai_v2_agent_ai_chatbot_chat", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'private'" + }, + "agent_mode": { + "name": "agent_mode", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'interactive'" + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "ai_style": { + "name": "ai_style", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'concise'" + }, + "ai_persona": { + "name": "ai_persona", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'general'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_document": { + "name": "pdr_ai_v2_agent_ai_chatbot_document", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'text'" + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "task_id": { + "name": "task_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_document_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_document_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_document", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_agent_ai_chatbot_document_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_document_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_document", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_task", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pdr_ai_v2_agent_ai_chatbot_document_id_created_at_pk": { + "name": "pdr_ai_v2_agent_ai_chatbot_document_id_created_at_pk", + "columns": [ + "id", + "created_at" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_execution_step": { + "name": "pdr_ai_v2_agent_ai_chatbot_execution_step", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "step_number": { + "name": "step_number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "step_type": { + "name": "step_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reasoning": { + "name": "reasoning", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "agent_execution_step_task_step_idx": { + "name": "agent_execution_step_task_step_idx", + "columns": [ + { + "expression": "task_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "step_number", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_execution_step_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_execution_step_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_execution_step", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_task", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_memory": { + "name": "pdr_ai_v2_agent_ai_chatbot_memory", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "memory_type": { + "name": "memory_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "importance": { + "name": "importance", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5 + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "accessed_at": { + "name": "accessed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "agent_memory_chat_idx": { + "name": "agent_memory_chat_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "agent_memory_chat_type_idx": { + "name": "agent_memory_chat_type_idx", + "columns": [ + { + "expression": "chat_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "memory_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_memory_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_memory_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_memory", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_message": { + "name": "pdr_ai_v2_agent_ai_chatbot_message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "message_type": { + "name": "message_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'text'" + }, + "parent_message_id": { + "name": "parent_message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_message_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_message_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_message", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_suggestion": { + "name": "pdr_ai_v2_agent_ai_chatbot_suggestion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "document_created_at": { + "name": "document_created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "original_text": { + "name": "original_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "suggested_text": { + "name": "suggested_text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_resolved": { + "name": "is_resolved", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_suggestion_document_id_document_created_at_pdr_ai_v2_agent_ai_chatbot_document_id_created_at_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_suggestion_document_id_document_created_at_pdr_ai_v2_agent_ai_chatbot_document_id_created_at_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_suggestion", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_document", + "columnsFrom": [ + "document_id", + "document_created_at" + ], + "columnsTo": [ + "id", + "created_at" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_task": { + "name": "pdr_ai_v2_agent_ai_chatbot_task", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "objective": { + "name": "objective", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "priority": { + "name": "priority", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_task_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_task_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_task", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_tool_call": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_call", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "task_id": { + "name": "task_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "tool_name": { + "name": "tool_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "tool_input": { + "name": "tool_input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "tool_output": { + "name": "tool_output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "execution_time_ms": { + "name": "execution_time_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_tool_call_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_call_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_tool_call", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_agent_ai_chatbot_tool_call_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_call_task_id_pdr_ai_v2_agent_ai_chatbot_task_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_tool_call", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_task", + "columnsFrom": [ + "task_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_tool_registry": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_registry", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "category": { + "name": "category", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "schema": { + "name": "schema", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "is_enabled": { + "name": "is_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "required_permissions": { + "name": "required_permissions", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "rate_limit": { + "name": "rate_limit", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pdr_ai_v2_agent_ai_chatbot_tool_registry_name_unique": { + "name": "pdr_ai_v2_agent_ai_chatbot_tool_registry_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_agent_ai_chatbot_vote": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote", + "schema": "", + "columns": { + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "name": "message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "is_upvoted": { + "name": "is_upvoted", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "feedback": { + "name": "feedback", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_pdr_ai_v2_agent_ai_chatbot_chat_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_vote", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_chat", + "columnsFrom": [ + "chat_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_agent_ai_chatbot_vote_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote_message_id_pdr_ai_v2_agent_ai_chatbot_message_id_fk", + "tableFrom": "pdr_ai_v2_agent_ai_chatbot_vote", + "tableTo": "pdr_ai_v2_agent_ai_chatbot_message", + "columnsFrom": [ + "message_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_message_id_pk": { + "name": "pdr_ai_v2_agent_ai_chatbot_vote_chat_id_message_id_pk", + "columns": [ + "chat_id", + "message_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_ai_usage_daily": { + "name": "pdr_ai_v2_ai_usage_daily", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "feature": { + "name": "feature", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "route": { + "name": "route", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "model_id": { + "name": "model_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "owner": { + "name": "owner", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "calls": { + "name": "calls", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "input_tokens": { + "name": "input_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "output_tokens": { + "name": "output_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reasoning_tokens": { + "name": "reasoning_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cached_input_tokens": { + "name": "cached_input_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "priced_calls": { + "name": "priced_calls", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "cost_usd": { + "name": "cost_usd", + "type": "numeric(20, 10)", + "primaryKey": false, + "notNull": true, + "default": "'0'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "kind": { + "name": "kind", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'chat'" + }, + "weighted_tokens": { + "name": "weighted_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "ai_usage_daily_row_key": { + "name": "ai_usage_daily_row_key", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "feature", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "route", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "model_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "owner", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "ai_usage_daily_user_date_idx": { + "name": "ai_usage_daily_user_date_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_ai_usage_daily_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_ai_usage_daily_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_ai_usage_daily", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_member_ai_limits": { + "name": "pdr_ai_v2_member_ai_limits", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "monthly_tokens": { + "name": "monthly_tokens", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "name": "updated_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "member_ai_limits_company_user_idx": { + "name": "member_ai_limits_company_user_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_member_ai_limits_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_member_ai_limits_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_member_ai_limits", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_claude_artifacts": { + "name": "pdr_ai_v2_claude_artifacts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "updated_by_user_id": { + "name": "updated_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "folder": { + "name": "folder", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "'Unfiled'" + }, + "artifact_type": { + "name": "artifact_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'html'" + }, + "source_url": { + "name": "source_url", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": false + }, + "import_method": { + "name": "import_method", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'paste'" + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "content_hash": { + "name": "content_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "search_text": { + "name": "search_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "starred": { + "name": "starred", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "opened_at": { + "name": "opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "claude_artifacts_company_idx": { + "name": "claude_artifacts_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_company_updated_idx": { + "name": "claude_artifacts_company_updated_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_creator_idx": { + "name": "claude_artifacts_creator_idx", + "columns": [ + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_folder_idx": { + "name": "claude_artifacts_folder_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "folder", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "claude_artifacts_deleted_idx": { + "name": "claude_artifacts_deleted_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_claude_artifacts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_claude_artifacts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_claude_artifacts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_account": { + "name": "pdr_ai_v2_auth_account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "issuer": { + "name": "issuer", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_account_user_id_idx": { + "name": "auth_account_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_account_issuer_account_idx": { + "name": "auth_account_issuer_account_idx", + "columns": [ + { + "expression": "issuer", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_account_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_account_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_account", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_jwks": { + "name": "pdr_ai_v2_auth_jwks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "alg": { + "name": "alg", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "crv": { + "name": "crv", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_access_token": { + "name": "pdr_ai_v2_auth_oauth_access_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "authorization_code_id": { + "name": "authorization_code_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resources": { + "name": "resources", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "requested_user_info_claims": { + "name": "requested_user_info_claims", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "refresh_id": { + "name": "refresh_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked": { + "name": "revoked", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "confirmation": { + "name": "confirmation", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_oauth_access_token_token_unique": { + "name": "auth_oauth_access_token_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_access_token_client_id_idx": { + "name": "auth_oauth_access_token_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_access_token_session_id_idx": { + "name": "auth_oauth_access_token_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_access_token_user_id_idx": { + "name": "auth_oauth_access_token_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_access_token_authorization_code_id_idx": { + "name": "auth_oauth_access_token_authorization_code_id_idx", + "columns": [ + { + "expression": "authorization_code_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_access_token_refresh_id_idx": { + "name": "auth_oauth_access_token_refresh_id_idx", + "columns": [ + { + "expression": "refresh_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_oauth_access_token_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk": { + "name": "pdr_ai_v2_auth_oauth_access_token_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_access_token", + "tableTo": "pdr_ai_v2_auth_oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_access_token_session_id_pdr_ai_v2_auth_session_id_fk": { + "name": "pdr_ai_v2_auth_oauth_access_token_session_id_pdr_ai_v2_auth_session_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_access_token", + "tableTo": "pdr_ai_v2_auth_session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_access_token_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_oauth_access_token_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_access_token", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_access_token_refresh_id_pdr_ai_v2_auth_oauth_refresh_token_id_fk": { + "name": "pdr_ai_v2_auth_oauth_access_token_refresh_id_pdr_ai_v2_auth_oauth_refresh_token_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_access_token", + "tableTo": "pdr_ai_v2_auth_oauth_refresh_token", + "columnsFrom": [ + "refresh_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_client": { + "name": "pdr_ai_v2_auth_oauth_client", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_secret": { + "name": "client_secret", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "client_discovery_id": { + "name": "client_discovery_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disabled": { + "name": "disabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "skip_consent": { + "name": "skip_consent", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "enable_end_session": { + "name": "enable_end_session", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "subject_type": { + "name": "subject_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "client_credentials_scopes": { + "name": "client_credentials_scopes", + "type": "text[]", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "uri": { + "name": "uri", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "contacts": { + "name": "contacts", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "tos": { + "name": "tos", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "policy": { + "name": "policy", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_id": { + "name": "software_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_version": { + "name": "software_version", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "software_statement": { + "name": "software_statement", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "redirect_uris": { + "name": "redirect_uris", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "post_logout_redirect_uris": { + "name": "post_logout_redirect_uris", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "backchannel_logout_uri": { + "name": "backchannel_logout_uri", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "backchannel_logout_session_required": { + "name": "backchannel_logout_session_required", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "token_endpoint_auth_method": { + "name": "token_endpoint_auth_method", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "application_type": { + "name": "application_type", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "jwks": { + "name": "jwks", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "jwks_uri": { + "name": "jwks_uri", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "grant_types": { + "name": "grant_types", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "response_types": { + "name": "response_types", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "require_pkce": { + "name": "require_pkce", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "dpop_bound_access_tokens": { + "name": "dpop_bound_access_tokens", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "auth_oauth_client_user_id_idx": { + "name": "auth_oauth_client_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_oauth_client_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_oauth_client_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_client", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "auth_oauth_client_client_id_unique": { + "name": "auth_oauth_client_client_id_unique", + "nullsNotDistinct": false, + "columns": [ + "client_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_client_assertion": { + "name": "pdr_ai_v2_auth_oauth_client_assertion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_client_resource": { + "name": "pdr_ai_v2_auth_oauth_client_resource", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "auth_oauth_client_resource_client_resource_unique": { + "name": "auth_oauth_client_resource_client_resource_unique", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_client_resource_client_id_idx": { + "name": "auth_oauth_client_resource_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_client_resource_resource_id_idx": { + "name": "auth_oauth_client_resource_resource_id_idx", + "columns": [ + { + "expression": "resource_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_oauth_client_resource_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk": { + "name": "pdr_ai_v2_auth_oauth_client_resource_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_client_resource", + "tableTo": "pdr_ai_v2_auth_oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_client_resource_resource_id_pdr_ai_v2_auth_oauth_resource_identifier_fk": { + "name": "pdr_ai_v2_auth_oauth_client_resource_resource_id_pdr_ai_v2_auth_oauth_resource_identifier_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_client_resource", + "tableTo": "pdr_ai_v2_auth_oauth_resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "identifier" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_consent": { + "name": "pdr_ai_v2_auth_oauth_consent", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resources": { + "name": "resources", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "requested_user_info_claims": { + "name": "requested_user_info_claims", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "auth_oauth_consent_client_id_idx": { + "name": "auth_oauth_consent_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_consent_user_id_idx": { + "name": "auth_oauth_consent_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_oauth_consent_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk": { + "name": "pdr_ai_v2_auth_oauth_consent_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_consent", + "tableTo": "pdr_ai_v2_auth_oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_consent_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_oauth_consent_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_consent", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_refresh_token": { + "name": "pdr_ai_v2_auth_oauth_refresh_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "reference_id": { + "name": "reference_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "authorization_code_id": { + "name": "authorization_code_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resources": { + "name": "resources", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "requested_user_info_claims": { + "name": "requested_user_info_claims", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked": { + "name": "revoked", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "rotated_at": { + "name": "rotated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "rotation_replay_response": { + "name": "rotation_replay_response", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rotation_replay_expires_at": { + "name": "rotation_replay_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "auth_time": { + "name": "auth_time", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "confirmation": { + "name": "confirmation", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_oauth_refresh_token_token_unique": { + "name": "auth_oauth_refresh_token_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_refresh_token_client_id_idx": { + "name": "auth_oauth_refresh_token_client_id_idx", + "columns": [ + { + "expression": "client_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_refresh_token_session_id_idx": { + "name": "auth_oauth_refresh_token_session_id_idx", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_refresh_token_user_id_idx": { + "name": "auth_oauth_refresh_token_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_oauth_refresh_token_authorization_code_id_idx": { + "name": "auth_oauth_refresh_token_authorization_code_id_idx", + "columns": [ + { + "expression": "authorization_code_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_oauth_refresh_token_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk": { + "name": "pdr_ai_v2_auth_oauth_refresh_token_client_id_pdr_ai_v2_auth_oauth_client_client_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_refresh_token", + "tableTo": "pdr_ai_v2_auth_oauth_client", + "columnsFrom": [ + "client_id" + ], + "columnsTo": [ + "client_id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_refresh_token_session_id_pdr_ai_v2_auth_session_id_fk": { + "name": "pdr_ai_v2_auth_oauth_refresh_token_session_id_pdr_ai_v2_auth_session_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_refresh_token", + "tableTo": "pdr_ai_v2_auth_session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_auth_oauth_refresh_token_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_oauth_refresh_token_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_oauth_refresh_token", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_oauth_resource": { + "name": "pdr_ai_v2_auth_oauth_resource", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token_ttl": { + "name": "access_token_ttl", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "refresh_token_ttl": { + "name": "refresh_token_ttl", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "signing_algorithm": { + "name": "signing_algorithm", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "signing_key_id": { + "name": "signing_key_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "allowed_scopes": { + "name": "allowed_scopes", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "custom_claims": { + "name": "custom_claims", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "dpop_bound_access_tokens_required": { + "name": "dpop_bound_access_tokens_required", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "disabled": { + "name": "disabled", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "policy_version": { + "name": "policy_version", + "type": "integer", + "primaryKey": false, + "notNull": false, + "default": 1 + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "auth_oauth_resource_identifier_unique": { + "name": "auth_oauth_resource_identifier_unique", + "nullsNotDistinct": false, + "columns": [ + "identifier" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_session": { + "name": "pdr_ai_v2_auth_session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_session_token_unique": { + "name": "auth_session_token_unique", + "columns": [ + { + "expression": "token", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "auth_session_user_id_idx": { + "name": "auth_session_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_auth_session_user_id_pdr_ai_v2_auth_user_id_fk": { + "name": "pdr_ai_v2_auth_session_user_id_pdr_ai_v2_auth_user_id_fk", + "tableFrom": "pdr_ai_v2_auth_session", + "tableTo": "pdr_ai_v2_auth_user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_user": { + "name": "pdr_ai_v2_auth_user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_user_email_unique": { + "name": "auth_user_email_unique", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_auth_verification": { + "name": "pdr_ai_v2_auth_verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "auth_verification_identifier_idx": { + "name": "auth_verification_identifier_idx", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_brand_channels": { + "name": "pdr_ai_v2_brand_channels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "handle": { + "name": "handle", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "profile_url": { + "name": "profile_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "capabilities": { + "name": "capabilities", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "status_reason": { + "name": "status_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "followers": { + "name": "followers", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "synced_at": { + "name": "synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "brand_channels_company_platform_external_unique": { + "name": "brand_channels_company_platform_external_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "platform", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_channels_connection_idx": { + "name": "brand_channels_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_channels_avatar_url_idx": { + "name": "brand_channels_avatar_url_idx", + "columns": [ + { + "expression": "avatar_url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": true, + "method": "hash", + "with": {} + }, + "brand_channels_avatar_file_id_idx": { + "name": "brand_channels_avatar_file_id_idx", + "columns": [ + { + "expression": "((regexp_match(\"avatar_url\", '/api/files/0*([0-9]+)([/?#]|$)'))[1])", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": true, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_brand_channels_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_brand_channels_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_brand_channels", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_brand_channels_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_brand_channels_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_brand_channels", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_brand_comments": { + "name": "pdr_ai_v2_brand_comments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "post_id": { + "name": "post_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "parent_external_id": { + "name": "parent_external_id", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "refs": { + "name": "refs", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "author_external_id": { + "name": "author_external_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "author_name": { + "name": "author_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "author_handle": { + "name": "author_handle", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "is_own": { + "name": "is_own", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "commented_at": { + "name": "commented_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "handled_at": { + "name": "handled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "handled_by_user_id": { + "name": "handled_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "brand_comments_channel_external_unique": { + "name": "brand_comments_channel_external_unique", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_comments_company_open_idx": { + "name": "brand_comments_company_open_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "handled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_comments_post_idx": { + "name": "brand_comments_post_idx", + "columns": [ + { + "expression": "post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_brand_comments_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_brand_comments_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_brand_comments", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_brand_comments_channel_id_pdr_ai_v2_brand_channels_id_fk": { + "name": "pdr_ai_v2_brand_comments_channel_id_pdr_ai_v2_brand_channels_id_fk", + "tableFrom": "pdr_ai_v2_brand_comments", + "tableTo": "pdr_ai_v2_brand_channels", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_brand_comments_post_id_pdr_ai_v2_brand_posts_id_fk": { + "name": "pdr_ai_v2_brand_comments_post_id_pdr_ai_v2_brand_posts_id_fk", + "tableFrom": "pdr_ai_v2_brand_comments", + "tableTo": "pdr_ai_v2_brand_posts", + "columnsFrom": [ + "post_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_brand_media": { + "name": "pdr_ai_v2_brand_media", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "uploaded_by_user_id": { + "name": "uploaded_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "storage_url": { + "name": "storage_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "size": { + "name": "size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(300)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "brand_media_company_idx": { + "name": "brand_media_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_media_storage_url_idx": { + "name": "brand_media_storage_url_idx", + "columns": [ + { + "expression": "storage_url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": true, + "method": "hash", + "with": {} + }, + "brand_media_storage_file_id_idx": { + "name": "brand_media_storage_file_id_idx", + "columns": [ + { + "expression": "((regexp_match(\"storage_url\", '/api/files/0*([0-9]+)([/?#]|$)'))[1])", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": true, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_brand_media_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_brand_media_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_brand_media", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_agent_persona": { + "name": "pdr_ai_v2_collab_agent_persona", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "system_prompt": { + "name": "system_prompt", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "node_id": { + "name": "node_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "route": { + "name": "route", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "temperature_x100": { + "name": "temperature_x100", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_turn_chars": { + "name": "max_turn_chars", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "accent": { + "name": "accent", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "autonomy": { + "name": "autonomy", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mode": { + "name": "mode", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "tools": { + "name": "tools", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "style": { + "name": "style", + "type": "varchar(24)", + "primaryKey": false, + "notNull": false + }, + "builtin": { + "name": "builtin", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "avatar_url": { + "name": "avatar_url", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "collab_persona_company_key_idx": { + "name": "collab_persona_company_key_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_persona_avatar_url_idx": { + "name": "collab_persona_avatar_url_idx", + "columns": [ + { + "expression": "avatar_url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": true, + "method": "hash", + "with": {} + }, + "collab_persona_avatar_file_id_idx": { + "name": "collab_persona_avatar_file_id_idx", + "columns": [ + { + "expression": "((regexp_match(\"avatar_url\", '/api/files/0*([0-9]+)([/?#]|$)'))[1])", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": true, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_agent_persona_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_agent_persona_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_agent_persona", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_channel": { + "name": "pdr_ai_v2_collab_channel", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "varchar(96)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "topic": { + "name": "topic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "archived": { + "name": "archived", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "collab_channel_company_slug_idx": { + "name": "collab_channel_company_slug_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slug", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_channel_company_idx": { + "name": "collab_channel_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_channel_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_channel_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_channel", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_meeting": { + "name": "pdr_ai_v2_collab_meeting", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "objective": { + "name": "objective", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "agenda": { + "name": "agenda", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "participants": { + "name": "participants", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "turn_policy": { + "name": "turn_policy", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'round_robin'" + }, + "moderator_persona_id": { + "name": "moderator_persona_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "max_turns": { + "name": "max_turns", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 12 + }, + "completion_marker": { + "name": "completion_marker", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'scheduled'" + }, + "turn_index": { + "name": "turn_index", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_speaker_id": { + "name": "next_speaker_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "controller": { + "name": "controller", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "slack_channel_id": { + "name": "slack_channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "slack_mirror_enabled": { + "name": "slack_mirror_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "slack_use_agent_identity": { + "name": "slack_use_agent_identity", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "ended_at": { + "name": "ended_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "workflow_key": { + "name": "workflow_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "phases": { + "name": "phases", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "collab_meeting_company_idx": { + "name": "collab_meeting_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_meeting_channel_idx": { + "name": "collab_meeting_channel_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_meeting_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_meeting_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_meeting", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_collab_meeting_channel_id_pdr_ai_v2_collab_channel_id_fk": { + "name": "pdr_ai_v2_collab_meeting_channel_id_pdr_ai_v2_collab_channel_id_fk", + "tableFrom": "pdr_ai_v2_collab_meeting", + "tableTo": "pdr_ai_v2_collab_channel", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_message": { + "name": "pdr_ai_v2_collab_message", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "author_kind": { + "name": "author_kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "author_name": { + "name": "author_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "on_behalf_of_persona_id": { + "name": "on_behalf_of_persona_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true, + "default": "'chat'" + }, + "thread_id": { + "name": "thread_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "slack_ts": { + "name": "slack_ts", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "meta": { + "name": "meta", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "collab_message_channel_seq_idx": { + "name": "collab_message_channel_seq_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "collab_message_channel_created_idx": { + "name": "collab_message_channel_created_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_message_channel_id_pdr_ai_v2_collab_channel_id_fk": { + "name": "pdr_ai_v2_collab_message_channel_id_pdr_ai_v2_collab_channel_id_fk", + "tableFrom": "pdr_ai_v2_collab_message", + "tableTo": "pdr_ai_v2_collab_channel", + "columnsFrom": [ + "channel_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_collab_node": { + "name": "pdr_ai_v2_collab_node", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "label": { + "name": "label", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "persona_ids": { + "name": "persona_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_remote_address": { + "name": "last_remote_address", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "collab_node_company_idx": { + "name": "collab_node_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_collab_node_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_collab_node_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_collab_node", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_connector_connections": { + "name": "pdr_ai_v2_connector_connections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "provider_account_id": { + "name": "provider_account_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "provider_account_email": { + "name": "provider_account_email", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "granted_by_user_id": { + "name": "granted_by_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "refresh_token_ciphertext": { + "name": "refresh_token_ciphertext", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "encryption_key_version": { + "name": "encryption_key_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "scopes": { + "name": "scopes", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "last_refresh_error": { + "name": "last_refresh_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "access_token_ciphertext": { + "name": "access_token_ciphertext", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "owner_user_id": { + "name": "owner_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "connector_connections_company_provider_account_unique": { + "name": "connector_connections_company_provider_account_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_account_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "connector_connections_company_provider_idx": { + "name": "connector_connections_company_provider_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "connector_connections_company_provider_owner_unique": { + "name": "connector_connections_company_provider_owner_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "owner_user_id is not null and provider = 'gmail'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "connector_connections_company_outlook_owner_unique": { + "name": "connector_connections_company_outlook_owner_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "owner_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "owner_user_id is not null and provider = 'outlook'", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_connector_connections_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_connector_connections_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_connector_connections", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_connector_connections_granted_by_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_connector_connections_granted_by_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_connector_connections", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "granted_by_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_connector_connections_owner_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_connector_connections_owner_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_connector_connections", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "owner_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_connector_deleted_item": { + "name": "pdr_ai_v2_connector_deleted_item", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "source_id": { + "name": "source_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "picked_root_id": { + "name": "picked_root_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "deleted_by_user_pk": { + "name": "deleted_by_user_pk", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "connector_deleted_item_conn_source_idx": { + "name": "connector_deleted_item_conn_source_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_connector_deleted_item_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_connector_deleted_item_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_connector_deleted_item", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_connector_deleted_item_deleted_by_user_pk_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_connector_deleted_item_deleted_by_user_pk_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_connector_deleted_item", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "deleted_by_user_pk" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_drive_links": { + "name": "pdr_ai_v2_document_drive_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "linked_by_user_id": { + "name": "linked_by_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "drive_file_id": { + "name": "drive_file_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "drive_web_view_link": { + "name": "drive_web_view_link", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "base_version_id": { + "name": "base_version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_synced_version_id": { + "name": "last_synced_version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_synced_revision_id": { + "name": "last_synced_revision_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "last_synced_md5": { + "name": "last_synced_md5", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'linked'" + }, + "fidelity_warning": { + "name": "fidelity_warning", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_checked_at": { + "name": "last_checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "origin": { + "name": "origin", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'linked'" + } + }, + "indexes": { + "document_drive_links_document_unique": { + "name": "document_drive_links_document_unique", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_drive_links_connection_idx": { + "name": "document_drive_links_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_drive_links_status_checked_idx": { + "name": "document_drive_links_status_checked_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_checked_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_drive_links_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_document_drive_links_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_document_drive_links", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_drive_links_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_document_drive_links_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_document_drive_links", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_drive_links_linked_by_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_document_drive_links_linked_by_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_document_drive_links", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "linked_by_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_drive_links_base_version_id_pdr_ai_v2_document_versions_id_fk": { + "name": "pdr_ai_v2_document_drive_links_base_version_id_pdr_ai_v2_document_versions_id_fk", + "tableFrom": "pdr_ai_v2_document_drive_links", + "tableTo": "pdr_ai_v2_document_versions", + "columnsFrom": [ + "base_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_drive_links_last_synced_version_id_pdr_ai_v2_document_versions_id_fk": { + "name": "pdr_ai_v2_document_drive_links_last_synced_version_id_pdr_ai_v2_document_versions_id_fk", + "tableFrom": "pdr_ai_v2_document_drive_links", + "tableTo": "pdr_ai_v2_document_versions", + "columnsFrom": [ + "last_synced_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_gmail_sync_scope": { + "name": "pdr_ai_v2_gmail_sync_scope", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "gmail_scope_conn_kind_value_idx": { + "name": "gmail_scope_conn_kind_value_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "value", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gmail_scope_connection_idx": { + "name": "gmail_scope_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_gmail_sync_scope_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_gmail_sync_scope_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_gmail_sync_scope", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_gmail_sync_state": { + "name": "pdr_ai_v2_gmail_sync_state", + "schema": "", + "columns": { + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "history_id": { + "name": "history_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_sync_status": { + "name": "last_sync_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_report": { + "name": "last_sync_report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sync_locked_at": { + "name": "sync_locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_gmail_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_gmail_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_gmail_sync_state", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_google_drive_picked_item": { + "name": "pdr_ai_v2_google_drive_picked_item", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "file_id": { + "name": "file_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "added_by_user_pk": { + "name": "added_by_user_pk", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "folder_category_id": { + "name": "folder_category_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "destination": { + "name": "destination", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "gdrive_picked_conn_file_idx": { + "name": "gdrive_picked_conn_file_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "file_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "gdrive_picked_connection_idx": { + "name": "gdrive_picked_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_google_drive_picked_item_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_google_drive_picked_item_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_google_drive_picked_item", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_google_drive_picked_item_added_by_user_pk_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_google_drive_picked_item_added_by_user_pk_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_google_drive_picked_item", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "added_by_user_pk" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_google_drive_sync_state": { + "name": "pdr_ai_v2_google_drive_sync_state", + "schema": "", + "columns": { + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "start_page_token": { + "name": "start_page_token", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_sync_status": { + "name": "last_sync_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_report": { + "name": "last_sync_report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sync_locked_at": { + "name": "sync_locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_google_drive_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_google_drive_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_google_drive_sync_state", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_microsoft365_picked_item": { + "name": "pdr_ai_v2_microsoft365_picked_item", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "drive_id": { + "name": "drive_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "item_id": { + "name": "item_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "web_url": { + "name": "web_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "added_by_user_pk": { + "name": "added_by_user_pk", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "folder_category_id": { + "name": "folder_category_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "destination": { + "name": "destination", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "m365_picked_conn_drive_item_idx": { + "name": "m365_picked_conn_drive_item_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "drive_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "item_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "m365_picked_connection_idx": { + "name": "m365_picked_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_microsoft365_picked_item_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_microsoft365_picked_item_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_microsoft365_picked_item", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_microsoft365_picked_item_added_by_user_pk_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_microsoft365_picked_item_added_by_user_pk_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_microsoft365_picked_item", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "added_by_user_pk" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_microsoft365_sync_state": { + "name": "pdr_ai_v2_microsoft365_sync_state", + "schema": "", + "columns": { + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_sync_status": { + "name": "last_sync_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_report": { + "name": "last_sync_report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sync_locked_at": { + "name": "sync_locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_microsoft365_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_microsoft365_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_microsoft365_sync_state", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_notion_sync_state": { + "name": "pdr_ai_v2_notion_sync_state", + "schema": "", + "columns": { + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "folder_category_id": { + "name": "folder_category_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_sync_status": { + "name": "last_sync_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_report": { + "name": "last_sync_report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sync_locked_at": { + "name": "sync_locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_notion_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_notion_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_notion_sync_state", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_outlook_sync_scope": { + "name": "pdr_ai_v2_outlook_sync_scope", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "outlook_scope_conn_kind_value_idx": { + "name": "outlook_scope_conn_kind_value_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "value", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "outlook_scope_connection_idx": { + "name": "outlook_scope_connection_idx", + "columns": [ + { + "expression": "connection_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_outlook_sync_scope_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_outlook_sync_scope_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_outlook_sync_scope", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_outlook_sync_state": { + "name": "pdr_ai_v2_outlook_sync_state", + "schema": "", + "columns": { + "connection_id": { + "name": "connection_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "delta_links": { + "name": "delta_links", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "last_sync_at": { + "name": "last_sync_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_sync_status": { + "name": "last_sync_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "last_sync_error": { + "name": "last_sync_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_sync_report": { + "name": "last_sync_report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "sync_locked_at": { + "name": "sync_locked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_outlook_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk": { + "name": "pdr_ai_v2_outlook_sync_state_connection_id_pdr_ai_v2_connector_connections_id_fk", + "tableFrom": "pdr_ai_v2_outlook_sync_state", + "tableTo": "pdr_ai_v2_connector_connections", + "columnsFrom": [ + "connection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_accounts": { + "name": "pdr_ai_v2_token_accounts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "balance_tokens": { + "name": "balance_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lifetime_tokens_purchased": { + "name": "lifetime_tokens_purchased", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lifetime_tokens_granted": { + "name": "lifetime_tokens_granted", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "lifetime_tokens_used": { + "name": "lifetime_tokens_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "token_accounts_company_id_idx": { + "name": "token_accounts_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_accounts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_accounts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_accounts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_grants": { + "name": "pdr_ai_v2_token_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "grant_type": { + "name": "grant_type", + "type": "varchar(30)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "granted_by": { + "name": "granted_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "token_grants_company_id_idx": { + "name": "token_grants_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_grants_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_grants_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_grants", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_transactions": { + "name": "pdr_ai_v2_token_transactions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "name": "amount", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "balance_after": { + "name": "balance_after", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "service": { + "name": "service", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false + }, + "reference_id": { + "name": "reference_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "token_tx_company_created_idx": { + "name": "token_tx_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "token_tx_company_service_idx": { + "name": "token_tx_company_service_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "service", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_transactions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_transactions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_transactions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_token_usage_daily": { + "name": "pdr_ai_v2_token_usage_daily", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "date": { + "name": "date", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "service": { + "name": "service", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true + }, + "operation_count": { + "name": "operation_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "tokens_used": { + "name": "tokens_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "token_usage_daily_company_date_service_idx": { + "name": "token_usage_daily_company_date_service_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "date", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "service", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_token_usage_daily_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_token_usage_daily_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_token_usage_daily", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_chat_history": { + "name": "pdr_ai_v2_chat_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_title": { + "name": "document_title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "response": { + "name": "response", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "chat_id": { + "name": "chat_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "query_type": { + "name": "query_type", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false, + "default": "'simple'" + }, + "pages": { + "name": "pages", + "type": "integer[]", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "chat_history_user_id_idx": { + "name": "chat_history_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_history_user_id_created_at_idx": { + "name": "chat_history_user_id_created_at_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "chat_history_document_id_idx": { + "name": "chat_history_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_chat_history_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_chat_history_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_chat_history", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_reference_resolutions": { + "name": "pdr_ai_v2_document_reference_resolutions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "reference_name": { + "name": "reference_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "resolved_in_document_id": { + "name": "resolved_in_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "resolution_details": { + "name": "resolution_details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "document_reference_resolutions_company_ref_idx": { + "name": "document_reference_resolutions_company_ref_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_reference_resolutions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_reference_resolutions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_reference_resolutions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_views": { + "name": "pdr_ai_v2_document_views", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "viewed_at": { + "name": "viewed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "document_views_document_id_idx": { + "name": "document_views_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_views_company_id_idx": { + "name": "document_views_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_views_user_id_idx": { + "name": "document_views_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_views_company_id_viewed_at_idx": { + "name": "document_views_company_id_viewed_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "viewed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_document_views_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_document_views_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_document_views", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_document_views_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_document_views_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_document_views", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_generated_documents": { + "name": "pdr_ai_v2_generated_documents", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "template_id": { + "name": "template_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "citations": { + "name": "citations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "generated_documents_user_id_idx": { + "name": "generated_documents_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "generated_documents_company_id_idx": { + "name": "generated_documents_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "generated_documents_company_user_idx": { + "name": "generated_documents_company_user_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_generated_documents_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_generated_documents_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_generated_documents", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_predictive_document_analysis_results": { + "name": "pdr_ai_v2_predictive_document_analysis_results", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "analysis_type": { + "name": "analysis_type", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "include_related_docs": { + "name": "include_related_docs", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "result_json": { + "name": "result_json", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "predictive_analysis_document_id_idx": { + "name": "predictive_analysis_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "predictive_analysis_document_version_idx": { + "name": "predictive_analysis_document_version_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_predictive_document_analysis_results_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_predictive_document_analysis_results_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_predictive_document_analysis_results", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_predictive_document_analysis_results_version_id_pdr_ai_v2_document_versions_id_fk": { + "name": "pdr_ai_v2_predictive_document_analysis_results_version_id_pdr_ai_v2_document_versions_id_fk", + "tableFrom": "pdr_ai_v2_predictive_document_analysis_results", + "tableTo": "pdr_ai_v2_document_versions", + "columnsFrom": [ + "version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_note_embeddings": { + "name": "pdr_ai_v2_document_note_embeddings", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "note_id": { + "name": "note_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "token_count": { + "name": "token_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "embedding": { + "name": "embedding", + "type": "vector(1536)", + "primaryKey": false, + "notNull": false + }, + "embedding_short": { + "name": "embedding_short", + "type": "vector(512)", + "primaryKey": false, + "notNull": false + }, + "model_version": { + "name": "model_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "doc_note_emb_note_id_idx": { + "name": "doc_note_emb_note_id_idx", + "columns": [ + { + "expression": "note_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_user_id_idx": { + "name": "doc_note_emb_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_document_id_idx": { + "name": "doc_note_emb_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_company_id_idx": { + "name": "doc_note_emb_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "doc_note_emb_embedding_short_idx": { + "name": "doc_note_emb_embedding_short_idx", + "columns": [ + { + "expression": "embedding_short", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "vector_cosine_ops" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hnsw", + "with": { + "m": 16, + "ef_construction": 64 + } + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_document_notes": { + "name": "pdr_ai_v2_document_notes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content_rich": { + "name": "content_rich", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "content_markdown": { + "name": "content_markdown", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "anchor": { + "name": "anchor", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "anchor_status": { + "name": "anchor_status", + "type": "varchar(24)", + "primaryKey": false, + "notNull": false, + "default": "'resolved'" + }, + "tags": { + "name": "tags", + "type": "text[]", + "primaryKey": false, + "notNull": false, + "default": "'{}'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "document_notes_user_idx": { + "name": "document_notes_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_document_idx": { + "name": "document_notes_document_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_company_idx": { + "name": "document_notes_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_version_idx": { + "name": "document_notes_version_idx", + "columns": [ + { + "expression": "version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "document_notes_anchor_status_idx": { + "name": "document_notes_anchor_status_idx", + "columns": [ + { + "expression": "anchor_status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_note_links": { + "name": "pdr_ai_v2_note_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "source_note_id": { + "name": "source_note_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "target_type": { + "name": "target_type", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true + }, + "target_note_id": { + "name": "target_note_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "target_document_id": { + "name": "target_document_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "target_title": { + "name": "target_title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "company_id": { + "name": "company_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "note_links_source_idx": { + "name": "note_links_source_idx", + "columns": [ + { + "expression": "source_note_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "note_links_target_note_idx": { + "name": "note_links_target_note_idx", + "columns": [ + { + "expression": "target_note_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "note_links_target_document_idx": { + "name": "note_links_target_document_idx", + "columns": [ + { + "expression": "target_document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "note_links_company_title_idx": { + "name": "note_links_company_title_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "target_title", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_feedback_attachments": { + "name": "pdr_ai_v2_feedback_attachments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "byte_size": { + "name": "byte_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "feedback_attachments_report_idx": { + "name": "feedback_attachments_report_idx", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_feedback_attachments_report_id_pdr_ai_v2_feedback_reports_id_fk": { + "name": "pdr_ai_v2_feedback_attachments_report_id_pdr_ai_v2_feedback_reports_id_fk", + "tableFrom": "pdr_ai_v2_feedback_attachments", + "tableTo": "pdr_ai_v2_feedback_reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_feedback_replies": { + "name": "pdr_ai_v2_feedback_replies", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "author_user_id": { + "name": "author_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "from_team": { + "name": "from_team", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "feedback_replies_report_created_idx": { + "name": "feedback_replies_report_created_idx", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_feedback_replies_report_id_pdr_ai_v2_feedback_reports_id_fk": { + "name": "pdr_ai_v2_feedback_replies_report_id_pdr_ai_v2_feedback_reports_id_fk", + "tableFrom": "pdr_ai_v2_feedback_replies", + "tableTo": "pdr_ai_v2_feedback_reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_feedback_reports": { + "name": "pdr_ai_v2_feedback_reports", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "severity": { + "name": "severity", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'new'" + }, + "reporter_user_id": { + "name": "reporter_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "vote_count": { + "name": "vote_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status_changed_at": { + "name": "status_changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_activity_at": { + "name": "last_activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "feedback_reports_kind_status_created_idx": { + "name": "feedback_reports_kind_status_created_idx", + "columns": [ + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "feedback_reports_reporter_idx": { + "name": "feedback_reports_reporter_idx", + "columns": [ + { + "expression": "reporter_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "feedback_reports_activity_idx": { + "name": "feedback_reports_activity_idx", + "columns": [ + { + "expression": "last_activity_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "feedback_reports_company_idx": { + "name": "feedback_reports_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_feedback_reports_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_feedback_reports_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_feedback_reports", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_feedback_votes": { + "name": "pdr_ai_v2_feedback_votes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "report_id": { + "name": "report_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "feedback_votes_report_user_unique": { + "name": "feedback_votes_report_user_unique", + "columns": [ + { + "expression": "report_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "feedback_votes_user_idx": { + "name": "feedback_votes_user_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_feedback_votes_report_id_pdr_ai_v2_feedback_reports_id_fk": { + "name": "pdr_ai_v2_feedback_votes_report_id_pdr_ai_v2_feedback_reports_id_fk", + "tableFrom": "pdr_ai_v2_feedback_votes", + "tableTo": "pdr_ai_v2_feedback_reports", + "columnsFrom": [ + "report_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_invite_codes": { + "name": "pdr_ai_v2_invite_codes", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_by": { + "name": "created_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "max_uses": { + "name": "max_uses", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "use_count": { + "name": "use_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "requires_approval": { + "name": "requires_approval", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "invite_codes_code_idx": { + "name": "invite_codes_code_idx", + "columns": [ + { + "expression": "code", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "invite_codes_company_id_idx": { + "name": "invite_codes_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_invite_codes_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_invite_codes_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_invite_codes", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pdr_ai_v2_invite_codes_code_unique": { + "name": "pdr_ai_v2_invite_codes_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_profile_images": { + "name": "pdr_ai_v2_profile_images", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(32)", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "byte_size": { + "name": "byte_size", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "width": { + "name": "width", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "height": { + "name": "height", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "profile_images_user_global_unique": { + "name": "profile_images_user_global_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "company_id is null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "profile_images_user_company_unique": { + "name": "profile_images_user_company_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "company_id is not null", + "concurrently": false, + "method": "btree", + "with": {} + }, + "profile_images_company_id_idx": { + "name": "profile_images_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_profile_images_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_profile_images_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_profile_images", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_profile_images_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_profile_images_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_profile_images", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_user_company_memberships": { + "name": "pdr_ai_v2_user_company_memberships", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "last_opened_at": { + "name": "last_opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "profile_display_name": { + "name": "profile_display_name", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "profile_title": { + "name": "profile_title", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "user_company_memberships_user_company_unique": { + "name": "user_company_memberships_user_company_unique", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_company_memberships_user_id_idx": { + "name": "user_company_memberships_user_id_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_company_memberships_company_id_idx": { + "name": "user_company_memberships_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "user_company_memberships_company_status_idx": { + "name": "user_company_memberships_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_user_company_memberships_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_user_company_memberships_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_user_company_memberships", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_user_company_memberships_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_user_company_memberships_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_user_company_memberships", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_users": { + "name": "pdr_ai_v2_users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "userId": { + "name": "userId", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "'member'" + }, + "status": { + "name": "status", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "last_active_at": { + "name": "last_active_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "display_name": { + "name": "display_name", + "type": "varchar(80)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(100)", + "primaryKey": false, + "notNull": false + }, + "pronouns": { + "name": "pronouns", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "time_zone": { + "name": "time_zone", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "bio": { + "name": "bio", + "type": "varchar(280)", + "primaryKey": false, + "notNull": false + }, + "provider_photo_checked_at": { + "name": "provider_photo_checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "users_company_id_idx": { + "name": "users_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "users_user_id_idx": { + "name": "users_user_id_idx", + "columns": [ + { + "expression": "userId", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_users_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_users_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_users", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pdr_ai_v2_users_userId_unique": { + "name": "pdr_ai_v2_users_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mindmap_presence": { + "name": "pdr_ai_v2_mindmap_presence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "mindmap_id": { + "name": "mindmap_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "display_name": { + "name": "display_name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "page_id": { + "name": "page_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "cursor_x": { + "name": "cursor_x", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "cursor_y": { + "name": "cursor_y", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "selection": { + "name": "selection", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "revision_seen": { + "name": "revision_seen", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "mindmap_presence_map_user_idx": { + "name": "mindmap_presence_map_user_idx", + "columns": [ + { + "expression": "mindmap_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmap_presence_seen_idx": { + "name": "mindmap_presence_seen_idx", + "columns": [ + { + "expression": "mindmap_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_seen_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mindmap_presence_mindmap_id_pdr_ai_v2_mindmaps_id_fk": { + "name": "pdr_ai_v2_mindmap_presence_mindmap_id_pdr_ai_v2_mindmaps_id_fk", + "tableFrom": "pdr_ai_v2_mindmap_presence", + "tableTo": "pdr_ai_v2_mindmaps", + "columnsFrom": [ + "mindmap_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mindmap_revisions": { + "name": "pdr_ai_v2_mindmap_revisions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "mindmap_id": { + "name": "mindmap_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "doc": { + "name": "doc", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "author_user_id": { + "name": "author_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "label": { + "name": "label", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "node_count": { + "name": "node_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "mindmap_revisions_map_idx": { + "name": "mindmap_revisions_map_idx", + "columns": [ + { + "expression": "mindmap_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "revision", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmap_revisions_created_idx": { + "name": "mindmap_revisions_created_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mindmap_revisions_mindmap_id_pdr_ai_v2_mindmaps_id_fk": { + "name": "pdr_ai_v2_mindmap_revisions_mindmap_id_pdr_ai_v2_mindmaps_id_fk", + "tableFrom": "pdr_ai_v2_mindmap_revisions", + "tableTo": "pdr_ai_v2_mindmaps", + "columnsFrom": [ + "mindmap_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mindmaps": { + "name": "pdr_ai_v2_mindmaps", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "updated_by_user_id": { + "name": "updated_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "template_id": { + "name": "template_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "folder": { + "name": "folder", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "'Unfiled'" + }, + "doc": { + "name": "doc", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "doc_version": { + "name": "doc_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "revision": { + "name": "revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "thumbnail": { + "name": "thumbnail", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "search_text": { + "name": "search_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "node_count": { + "name": "node_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "edge_count": { + "name": "edge_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "starred": { + "name": "starred", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "published_document_id": { + "name": "published_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "opened_at": { + "name": "opened_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "published_revision": { + "name": "published_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "mindmaps_company_idx": { + "name": "mindmaps_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_company_updated_idx": { + "name": "mindmaps_company_updated_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "updated_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_creator_idx": { + "name": "mindmaps_creator_idx", + "columns": [ + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_folder_idx": { + "name": "mindmaps_folder_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "folder", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mindmaps_deleted_idx": { + "name": "mindmaps_deleted_idx", + "columns": [ + { + "expression": "deleted_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mindmaps_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_mindmaps_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_mindmaps", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_session_grants": { + "name": "pdr_ai_v2_workspace_session_grants", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "principal_type": { + "name": "principal_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "principal_id": { + "name": "principal_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "level": { + "name": "level", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'view'" + }, + "granted_by": { + "name": "granted_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "workspace_session_grants_session_principal_uq": { + "name": "workspace_session_grants_session_principal_uq", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_session_grants_company_principal_idx": { + "name": "workspace_session_grants_company_principal_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "principal_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_session_grants_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_session_grants_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_session_grants", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_workspace_session_grants_session_id_pdr_ai_v2_workspace_sessions_id_fk": { + "name": "pdr_ai_v2_workspace_session_grants_session_id_pdr_ai_v2_workspace_sessions_id_fk", + "tableFrom": "pdr_ai_v2_workspace_session_grants", + "tableTo": "pdr_ai_v2_workspace_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_session_messages": { + "name": "pdr_ai_v2_workspace_session_messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "refs": { + "name": "refs", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "citations": { + "name": "citations", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "attachments": { + "name": "attachments", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar(120)", + "primaryKey": false, + "notNull": false + }, + "tokens": { + "name": "tokens", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "agent_key": { + "name": "agent_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_session_messages_session_seq_uq": { + "name": "workspace_session_messages_session_seq_uq", + "columns": [ + { + "expression": "session_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_session_messages_attachments_idx": { + "name": "workspace_session_messages_attachments_idx", + "columns": [ + { + "expression": "attachments", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "jsonb_path_ops" + } + ], + "isUnique": false, + "concurrently": true, + "method": "gin", + "with": {} + }, + "workspace_session_messages_metadata_idx": { + "name": "workspace_session_messages_metadata_idx", + "columns": [ + { + "expression": "metadata", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "jsonb_path_ops" + } + ], + "isUnique": false, + "concurrently": true, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_session_messages_session_id_pdr_ai_v2_workspace_sessions_id_fk": { + "name": "pdr_ai_v2_workspace_session_messages_session_id_pdr_ai_v2_workspace_sessions_id_fk", + "tableFrom": "pdr_ai_v2_workspace_session_messages", + "tableTo": "pdr_ai_v2_workspace_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_session_user_state": { + "name": "pdr_ai_v2_workspace_session_user_state", + "schema": "", + "columns": { + "session_id": { + "name": "session_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "pinned_at": { + "name": "pinned_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "pin_rank": { + "name": "pin_rank", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "archived_at": { + "name": "archived_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_seen_at": { + "name": "last_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "workspace_session_user_state_company_user_idx": { + "name": "workspace_session_user_state_company_user_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_session_user_state_session_id_pdr_ai_v2_workspace_sessions_id_fk": { + "name": "pdr_ai_v2_workspace_session_user_state_session_id_pdr_ai_v2_workspace_sessions_id_fk", + "tableFrom": "pdr_ai_v2_workspace_session_user_state", + "tableTo": "pdr_ai_v2_workspace_sessions", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_workspace_session_user_state_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_session_user_state_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_session_user_state", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pdr_ai_v2_workspace_session_user_state_session_id_user_id_pk": { + "name": "pdr_ai_v2_workspace_session_user_state_session_id_user_id_pk", + "columns": [ + "session_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_sessions": { + "name": "pdr_ai_v2_workspace_sessions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "context_source_ids": { + "name": "context_source_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "continuation": { + "name": "continuation", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "message_count": { + "name": "message_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "pinned": { + "name": "pinned", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "last_message_at": { + "name": "last_message_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "agent_key": { + "name": "agent_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "queued_messages": { + "name": "queued_messages", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "queue_revision": { + "name": "queue_revision", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "shared_at": { + "name": "shared_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "forked_from_session_id": { + "name": "forked_from_session_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "workspace_sessions_owner_recent_idx": { + "name": "workspace_sessions_owner_recent_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "last_message_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_sessions_company_idx": { + "name": "workspace_sessions_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "workspace_sessions_queued_messages_idx": { + "name": "workspace_sessions_queued_messages_idx", + "columns": [ + { + "expression": "queued_messages", + "isExpression": false, + "asc": true, + "nulls": "last", + "opclass": "jsonb_path_ops" + } + ], + "isUnique": false, + "concurrently": true, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_workspace_sessions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_sessions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_sessions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_settings_values": { + "name": "pdr_ai_v2_settings_values", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "scope_type": { + "name": "scope_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "scope_id": { + "name": "scope_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "key": { + "name": "key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "updated_by": { + "name": "updated_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "settings_values_scope_key_idx": { + "name": "settings_values_scope_key_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scope_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scope_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "settings_values_company_key_idx": { + "name": "settings_values_company_key_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_settings_values_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_settings_values_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_settings_values", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_assistant_conversations": { + "name": "pdr_ai_v2_assistant_conversations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "saved_by_user_id": { + "name": "saved_by_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "client": { + "name": "client", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "client_name": { + "name": "client_name", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "content_hash": { + "name": "content_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "message_count": { + "name": "message_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "follow_up_note_id": { + "name": "follow_up_note_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "follow_up_status": { + "name": "follow_up_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "follow_up_error": { + "name": "follow_up_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "assistant_conversations_document_unique": { + "name": "assistant_conversations_document_unique", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "assistant_conversations_company_saver_idx": { + "name": "assistant_conversations_company_saver_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "saved_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_assistant_conversations_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_assistant_conversations_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_assistant_conversations", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_assistant_conversations_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_assistant_conversations_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_assistant_conversations", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_assistant_conversations_saved_by_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_assistant_conversations_saved_by_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_assistant_conversations", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "saved_by_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mcp_access_keys": { + "name": "pdr_ai_v2_mcp_access_keys", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(80)", + "primaryKey": false, + "notNull": true + }, + "display_prefix": { + "name": "display_prefix", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "secret_hash": { + "name": "secret_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "scopes": { + "name": "scopes", + "type": "text[]", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "mcp_access_keys_secret_hash_unique": { + "name": "mcp_access_keys_secret_hash_unique", + "columns": [ + { + "expression": "secret_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_access_keys_company_user_idx": { + "name": "mcp_access_keys_company_user_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mcp_access_keys_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_mcp_access_keys_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_mcp_access_keys", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_mcp_access_keys_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_mcp_access_keys_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_mcp_access_keys", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mcp_oauth_workspace_choices": { + "name": "pdr_ai_v2_mcp_oauth_workspace_choices", + "schema": "", + "columns": { + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "flow_key": { + "name": "flow_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "chosen_at": { + "name": "chosen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_mcp_oauth_workspace_choices_session_id_pdr_ai_v2_auth_session_id_fk": { + "name": "pdr_ai_v2_mcp_oauth_workspace_choices_session_id_pdr_ai_v2_auth_session_id_fk", + "tableFrom": "pdr_ai_v2_mcp_oauth_workspace_choices", + "tableTo": "pdr_ai_v2_auth_session", + "columnsFrom": [ + "session_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_mcp_oauth_workspace_choices_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_mcp_oauth_workspace_choices_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_mcp_oauth_workspace_choices", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pdr_ai_v2_mcp_oauth_workspace_choices_session_id_flow_key_pk": { + "name": "pdr_ai_v2_mcp_oauth_workspace_choices_session_id_flow_key_pk", + "columns": [ + "session_id", + "flow_key" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_mcp_staged_files": { + "name": "pdr_ai_v2_mcp_staged_files", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(40)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "upload_token_hash": { + "name": "upload_token_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "upload_expires_at": { + "name": "upload_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "filename": { + "name": "filename", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "mime_type": { + "name": "mime_type", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "size_bytes": { + "name": "size_bytes", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "storage_url": { + "name": "storage_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "storage_provider": { + "name": "storage_provider", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "details": { + "name": "details", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "used_at": { + "name": "used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "mcp_staged_files_upload_token_unique": { + "name": "mcp_staged_files_upload_token_unique", + "columns": [ + { + "expression": "upload_token_hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_staged_files_company_user_idx": { + "name": "mcp_staged_files_company_user_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mcp_staged_files_expires_idx": { + "name": "mcp_staged_files_expires_idx", + "columns": [ + { + "expression": "expires_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_mcp_staged_files_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_mcp_staged_files_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_mcp_staged_files", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_mcp_staged_files_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_mcp_staged_files_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_mcp_staged_files", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_workspace_model_endpoints": { + "name": "pdr_ai_v2_workspace_model_endpoints", + "schema": "", + "columns": { + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "base_url": { + "name": "base_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "api_key_ciphertext": { + "name": "api_key_ciphertext", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "api_key_last4": { + "name": "api_key_last4", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "encryption_key_version": { + "name": "encryption_key_version", + "type": "smallint", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "models": { + "name": "models", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "connected_via": { + "name": "connected_via", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'key'" + }, + "updated_by_user_id": { + "name": "updated_by_user_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": { + "pdr_ai_v2_workspace_model_endpoints_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_workspace_model_endpoints_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_workspace_model_endpoints", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_workspace_model_endpoints_updated_by_user_id_pdr_ai_v2_users_id_fk": { + "name": "pdr_ai_v2_workspace_model_endpoints_updated_by_user_id_pdr_ai_v2_users_id_fk", + "tableFrom": "pdr_ai_v2_workspace_model_endpoints", + "tableTo": "pdr_ai_v2_users", + "columnsFrom": [ + "updated_by_user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_storage_deletion_items": { + "name": "pdr_ai_v2_storage_deletion_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "request_id": { + "name": "request_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "stored_object_id": { + "name": "stored_object_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "adapter": { + "name": "adapter", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "storage_location_id": { + "name": "storage_location_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "object_key": { + "name": "object_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source_url": { + "name": "source_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error_code": { + "name": "error_code", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "resolved_by": { + "name": "resolved_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "resolution_note": { + "name": "resolution_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "requeued_by": { + "name": "requeued_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "requeue_note": { + "name": "requeue_note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requeued_at": { + "name": "requeued_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "storage_deletion_items_request_url_unique": { + "name": "storage_deletion_items_request_url_unique", + "columns": [ + { + "expression": "request_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source_url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_deletion_items_state_idx": { + "name": "storage_deletion_items_state_idx", + "columns": [ + { + "expression": "state", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_deletion_items_stored_object_idx": { + "name": "storage_deletion_items_stored_object_idx", + "columns": [ + { + "expression": "stored_object_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_deletion_items_ref_idx": { + "name": "storage_deletion_items_ref_idx", + "columns": [ + { + "expression": "adapter", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "storage_location_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "object_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_deletion_items_source_url_idx": { + "name": "storage_deletion_items_source_url_idx", + "columns": [ + { + "expression": "source_url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hash", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_storage_deletion_items_request_id_pdr_ai_v2_storage_deletion_requests_id_fk": { + "name": "pdr_ai_v2_storage_deletion_items_request_id_pdr_ai_v2_storage_deletion_requests_id_fk", + "tableFrom": "pdr_ai_v2_storage_deletion_items", + "tableTo": "pdr_ai_v2_storage_deletion_requests", + "columnsFrom": [ + "request_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_storage_deletion_items_stored_object_id_pdr_ai_v2_storage_objects_id_fk": { + "name": "pdr_ai_v2_storage_deletion_items_stored_object_id_pdr_ai_v2_storage_objects_id_fk", + "tableFrom": "pdr_ai_v2_storage_deletion_items", + "tableTo": "pdr_ai_v2_storage_objects", + "columnsFrom": [ + "stored_object_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "storage_deletion_items_ref_check": { + "name": "storage_deletion_items_ref_check", + "value": "(\"pdr_ai_v2_storage_deletion_items\".\"adapter\" IS NOT NULL AND \"pdr_ai_v2_storage_deletion_items\".\"storage_location_id\" IS NOT NULL AND \"pdr_ai_v2_storage_deletion_items\".\"object_key\" IS NOT NULL) OR (\"pdr_ai_v2_storage_deletion_items\".\"state\" IN ('quarantined', 'skipped', 'waived') AND \"pdr_ai_v2_storage_deletion_items\".\"adapter\" IS NULL AND \"pdr_ai_v2_storage_deletion_items\".\"storage_location_id\" IS NULL AND \"pdr_ai_v2_storage_deletion_items\".\"object_key\" IS NULL)" + }, + "storage_deletion_items_state_check": { + "name": "storage_deletion_items_state_check", + "value": "\"pdr_ai_v2_storage_deletion_items\".\"state\" IN ('pending', 'deleted', 'not_found', 'retained', 'blocked', 'quarantined', 'skipped', 'waived')" + } + }, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_storage_deletion_requests": { + "name": "pdr_ai_v2_storage_deletion_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "document_version_id": { + "name": "document_version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "requested_by": { + "name": "requested_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "trace_id": { + "name": "trace_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "storage_deletion_requests_status_created_idx": { + "name": "storage_deletion_requests_status_created_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_deletion_requests_company_created_idx": { + "name": "storage_deletion_requests_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_deletion_requests_document_idx": { + "name": "storage_deletion_requests_document_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": { + "storage_deletion_requests_scope_check": { + "name": "storage_deletion_requests_scope_check", + "value": "\"pdr_ai_v2_storage_deletion_requests\".\"scope\" IN ('document', 'version', 'object')" + }, + "storage_deletion_requests_status_check": { + "name": "storage_deletion_requests_status_check", + "value": "\"pdr_ai_v2_storage_deletion_requests\".\"status\" IN ('pending', 'completed', 'blocked')" + } + }, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_storage_objects": { + "name": "pdr_ai_v2_storage_objects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "adapter": { + "name": "adapter", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "storage_location_id": { + "name": "storage_location_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "object_key": { + "name": "object_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "content_type": { + "name": "content_type", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "size_bytes": { + "name": "size_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "checksum": { + "name": "checksum", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "storage_objects_identity_unique": { + "name": "storage_objects_identity_unique", + "columns": [ + { + "expression": "adapter", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "storage_location_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "object_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "storage_objects_url_idx": { + "name": "storage_objects_url_idx", + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "hash", + "with": {} + }, + "storage_objects_company_created_idx": { + "name": "storage_objects_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_trend_search_jobs": { + "name": "pdr_ai_v2_trend_search_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company_context": { + "name": "company_context", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "results": { + "name": "results", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "trend_search_jobs_company_id_idx": { + "name": "trend_search_jobs_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "trend_search_jobs_status_idx": { + "name": "trend_search_jobs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "trend_search_jobs_company_status_idx": { + "name": "trend_search_jobs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_trend_search_jobs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_trend_search_jobs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_trend_search_jobs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_trend_search_cache": { + "name": "pdr_ai_v2_trend_search_cache", + "schema": "", + "columns": { + "cache_key": { + "name": "cache_key", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_client_prospector_jobs": { + "name": "pdr_ai_v2_client_prospector_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(50)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "query": { + "name": "query", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "company_context": { + "name": "company_context", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "location_lat": { + "name": "location_lat", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "location_lng": { + "name": "location_lng", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "radius": { + "name": "radius", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 5000 + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "results": { + "name": "results", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "client_prospector_jobs_company_id_idx": { + "name": "client_prospector_jobs_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "client_prospector_jobs_status_idx": { + "name": "client_prospector_jobs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "client_prospector_jobs_company_status_idx": { + "name": "client_prospector_jobs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_client_prospector_jobs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_client_prospector_jobs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_client_prospector_jobs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_company_metadata": { + "name": "pdr_ai_v2_company_metadata", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "schema_version": { + "name": "schema_version", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'1.0.0'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "last_extraction_document_id": { + "name": "last_extraction_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "build_status": { + "name": "build_status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'idle'" + }, + "build_error": { + "name": "build_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "build_started_at": { + "name": "build_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "built_at": { + "name": "built_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "company_metadata_company_id_unique": { + "name": "company_metadata_company_id_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_company_metadata_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_company_metadata_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_company_metadata_last_extraction_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_company_metadata_last_extraction_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "last_extraction_document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_company_metadata_history": { + "name": "pdr_ai_v2_company_metadata_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "change_type": { + "name": "change_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "diff": { + "name": "diff", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "changed_by": { + "name": "changed_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "company_metadata_history_company_id_idx": { + "name": "company_metadata_history_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_metadata_history_document_id_idx": { + "name": "company_metadata_history_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_metadata_history_created_at_idx": { + "name": "company_metadata_history_created_at_idx", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_metadata_history_change_type_idx": { + "name": "company_metadata_history_change_type_idx", + "columns": [ + { + "expression": "change_type", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_company_metadata_history_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_company_metadata_history_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata_history", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_company_metadata_history_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_company_metadata_history_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_company_metadata_history", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_company_profile_sources": { + "name": "pdr_ai_v2_company_profile_sources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "version_id": { + "name": "version_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "role_by": { + "name": "role_by", + "type": "varchar(8)", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "override": { + "name": "override", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "override_by": { + "name": "override_by", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "facts": { + "name": "facts", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "fact_count": { + "name": "fact_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "passages": { + "name": "passages", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "reader_version": { + "name": "reader_version", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "model_id": { + "name": "model_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "company_profile_sources_document_unique": { + "name": "company_profile_sources_document_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "company_profile_sources_document_id_idx": { + "name": "company_profile_sources_document_id_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_company_profile_sources_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_company_profile_sources_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_company_profile_sources", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_company_profile_sources_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_company_profile_sources_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_company_profile_sources", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_brand_posts": { + "name": "pdr_ai_v2_brand_posts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "scheduled_at": { + "name": "scheduled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "post_id": { + "name": "post_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "post_url": { + "name": "post_url", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "channel_id": { + "name": "channel_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "media": { + "name": "media", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metrics": { + "name": "metrics", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "metrics_at": { + "name": "metrics_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "brand_posts_company_status_idx": { + "name": "brand_posts_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_posts_company_scheduled_idx": { + "name": "brand_posts_company_scheduled_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_posts_due_idx": { + "name": "brand_posts_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scheduled_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "brand_posts_channel_idx": { + "name": "brand_posts_channel_idx", + "columns": [ + { + "expression": "channel_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_marketing_content_history": { + "name": "pdr_ai_v2_marketing_content_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "platform": { + "name": "platform", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "angle": { + "name": "angle", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "content_type": { + "name": "content_type", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "default": "'post'" + }, + "metadata": { + "name": "metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "impressions": { + "name": "impressions", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "engagements": { + "name": "engagements", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "clicks": { + "name": "clicks", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "post_id": { + "name": "post_id", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "post_url": { + "name": "post_url", + "type": "varchar(500)", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "mch_company_id_idx": { + "name": "mch_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "mch_platform_idx": { + "name": "mch_platform_idx", + "columns": [ + { + "expression": "platform", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_marketing_runs": { + "name": "pdr_ai_v2_marketing_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "debug": { + "name": "debug", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "events": { + "name": "events", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "checkpoints": { + "name": "checkpoints", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "heartbeat_at": { + "name": "heartbeat_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "marketing_runs_company_status_idx": { + "name": "marketing_runs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "marketing_runs_user_created_idx": { + "name": "marketing_runs_user_created_idx", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_marketing_runs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_marketing_runs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_marketing_runs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_founder_weekly_review_dispatches": { + "name": "pdr_ai_v2_founder_weekly_review_dispatches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "operation_key": { + "name": "operation_key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "generation_job_id": { + "name": "generation_job_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "generation_claim_id": { + "name": "generation_claim_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempt_count": { + "name": "attempt_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "available_at": { + "name": "available_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "dispatched_at": { + "name": "dispatched_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error_code": { + "name": "last_error_code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "founder_weekly_review_dispatches_run_operation_key_unique": { + "name": "founder_weekly_review_dispatches_run_operation_key_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_dispatches_event_id_unique": { + "name": "founder_weekly_review_dispatches_event_id_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_dispatches_pending_idx": { + "name": "founder_weekly_review_dispatches_pending_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "available_at", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_dispatches_company_run_idx": { + "name": "founder_weekly_review_dispatches_company_run_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_founder_weekly_review_dispatches_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_dispatches_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_dispatches", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_founder_weekly_review_dispatches_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_dispatches_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_dispatches", + "tableTo": "pdr_ai_v2_founder_weekly_review_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_founder_weekly_review_operations": { + "name": "pdr_ai_v2_founder_weekly_review_operations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "operation_type": { + "name": "operation_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "request_key": { + "name": "request_key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "source_failure_sequence": { + "name": "source_failure_sequence", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "founder_weekly_review_operations_run_type_request_key_unique": { + "name": "founder_weekly_review_operations_run_type_request_key_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_operations_company_run_created_at_idx": { + "name": "founder_weekly_review_operations_company_run_created_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_operations_run_type_created_at_idx": { + "name": "founder_weekly_review_operations_run_type_created_at_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "operation_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_founder_weekly_review_operations_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_operations_run_id_pdr_ai_v2_founder_weekly_review_runs_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_operations", + "tableTo": "pdr_ai_v2_founder_weekly_review_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_founder_weekly_review_operations_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_operations_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_operations", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_founder_weekly_review_runs": { + "name": "pdr_ai_v2_founder_weekly_review_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "request_key": { + "name": "request_key", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "reporting_period_start": { + "name": "reporting_period_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "reporting_period_end": { + "name": "reporting_period_end", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "review_payload": { + "name": "review_payload", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "review_schema_version": { + "name": "review_schema_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "evidence_snapshot": { + "name": "evidence_snapshot", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "evidence_schema_version": { + "name": "evidence_schema_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "model_metadata": { + "name": "model_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_by_actor_id": { + "name": "created_by_actor_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "retry_count": { + "name": "retry_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "failure_sequence": { + "name": "failure_sequence", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "generation_attempt": { + "name": "generation_attempt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "generation_claim_id": { + "name": "generation_claim_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "generation_job_id": { + "name": "generation_job_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "queued_at": { + "name": "queued_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "generation_started_at": { + "name": "generation_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "generated_at": { + "name": "generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "error_code": { + "name": "error_code", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "collection_input": { + "name": "collection_input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "collection_claim_id": { + "name": "collection_claim_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "collection_started_at": { + "name": "collection_started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "evidence_collected_at": { + "name": "evidence_collected_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "founder_weekly_review_runs_company_request_key_unique": { + "name": "founder_weekly_review_runs_company_request_key_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "request_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_company_created_at_idx": { + "name": "founder_weekly_review_runs_company_created_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_company_status_created_at_idx": { + "name": "founder_weekly_review_runs_company_status_created_at_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_company_period_idx": { + "name": "founder_weekly_review_runs_company_period_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reporting_period_start", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "reporting_period_end", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_claim_idx": { + "name": "founder_weekly_review_runs_claim_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation_claim_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "founder_weekly_review_runs_collection_claim_idx": { + "name": "founder_weekly_review_runs_collection_claim_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "collection_claim_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_founder_weekly_review_runs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_founder_weekly_review_runs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_founder_weekly_review_runs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_campaign_approvals": { + "name": "pdr_ai_v2_email_campaign_approvals", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "template_version_id": { + "name": "template_version_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "approved_by": { + "name": "approved_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "approved_by_email": { + "name": "approved_by_email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": false + }, + "approved_by_kind": { + "name": "approved_by_kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'human'" + }, + "review_verdict": { + "name": "review_verdict", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "override_reason": { + "name": "override_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_campaign_approvals_campaign_idx": { + "name": "email_campaign_approvals_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_campaign_approvals_version_idx": { + "name": "email_campaign_approvals_version_idx", + "columns": [ + { + "expression": "template_version_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_campaign_approvals_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_campaign_approvals_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_campaign_approvals", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_campaign_approvals_template_version_id_pdr_ai_v2_email_template_versions_id_fk": { + "name": "pdr_ai_v2_email_campaign_approvals_template_version_id_pdr_ai_v2_email_template_versions_id_fk", + "tableFrom": "pdr_ai_v2_email_campaign_approvals", + "tableTo": "pdr_ai_v2_email_template_versions", + "columnsFrom": [ + "template_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_campaigns": { + "name": "pdr_ai_v2_email_campaigns", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "goal": { + "name": "goal", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "approved_version_id": { + "name": "approved_version_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "automation_key": { + "name": "automation_key", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_campaigns_company_idx": { + "name": "email_campaigns_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_campaigns_company_status_idx": { + "name": "email_campaigns_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_campaigns_company_automation_key_uq": { + "name": "email_campaigns_company_automation_key_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "automation_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_campaigns_approved_version_id_pdr_ai_v2_email_template_versions_id_fk": { + "name": "pdr_ai_v2_email_campaigns_approved_version_id_pdr_ai_v2_email_template_versions_id_fk", + "tableFrom": "pdr_ai_v2_email_campaigns", + "tableTo": "pdr_ai_v2_email_template_versions", + "columnsFrom": [ + "approved_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_recipients": { + "name": "pdr_ai_v2_email_recipients", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "company": { + "name": "company", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "context_notes": { + "name": "context_notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "vars": { + "name": "vars", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "frozen_at": { + "name": "frozen_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_recipients_campaign_idx": { + "name": "email_recipients_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_recipients_campaign_email_uq": { + "name": "email_recipients_campaign_email_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_recipients_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_recipients_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_recipients", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_send_attempts": { + "name": "pdr_ai_v2_email_send_attempts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "template_version_id": { + "name": "template_version_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "mode": { + "name": "mode", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'dry_run'" + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'running'" + }, + "requested_by": { + "name": "requested_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "heartbeat_at": { + "name": "heartbeat_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "recipient_count": { + "name": "recipient_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "sent_count": { + "name": "sent_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "failed_count": { + "name": "failed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "suppressed_count": { + "name": "suppressed_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "skipped_count": { + "name": "skipped_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "email_send_attempts_campaign_idx": { + "name": "email_send_attempts_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_send_attempts_campaign_key_uq": { + "name": "email_send_attempts_campaign_key_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_send_attempts_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_send_attempts_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_send_attempts", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_send_attempts_template_version_id_pdr_ai_v2_email_template_versions_id_fk": { + "name": "pdr_ai_v2_email_send_attempts_template_version_id_pdr_ai_v2_email_template_versions_id_fk", + "tableFrom": "pdr_ai_v2_email_send_attempts", + "tableTo": "pdr_ai_v2_email_template_versions", + "columnsFrom": [ + "template_version_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_sends": { + "name": "pdr_ai_v2_email_sends", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attempt_id": { + "name": "attempt_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "recipient_id": { + "name": "recipient_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "recipient_email": { + "name": "recipient_email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "provider_message_id": { + "name": "provider_message_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "provider_idempotency_key": { + "name": "provider_idempotency_key", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_sends_campaign_idx": { + "name": "email_sends_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_sends_attempt_recipient_uq": { + "name": "email_sends_attempt_recipient_uq", + "columns": [ + { + "expression": "attempt_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipient_email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_sends_campaign_recipient_delivery_uq": { + "name": "email_sends_campaign_recipient_delivery_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "recipient_email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "status IN ('queued', 'sent')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_sends_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_sends_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_sends", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_sends_attempt_id_pdr_ai_v2_email_send_attempts_id_fk": { + "name": "pdr_ai_v2_email_sends_attempt_id_pdr_ai_v2_email_send_attempts_id_fk", + "tableFrom": "pdr_ai_v2_email_sends", + "tableTo": "pdr_ai_v2_email_send_attempts", + "columnsFrom": [ + "attempt_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_email_sends_recipient_id_pdr_ai_v2_email_recipients_id_fk": { + "name": "pdr_ai_v2_email_sends_recipient_id_pdr_ai_v2_email_recipients_id_fk", + "tableFrom": "pdr_ai_v2_email_sends", + "tableTo": "pdr_ai_v2_email_recipients", + "columnsFrom": [ + "recipient_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_suppressions": { + "name": "pdr_ai_v2_email_suppressions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(320)", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'unsubscribe'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_suppressions_company_email_uq": { + "name": "email_suppressions_company_email_uq", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_email_template_versions": { + "name": "pdr_ai_v2_email_template_versions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "campaign_id": { + "name": "campaign_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variables": { + "name": "variables", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'ai_generated'" + }, + "goal": { + "name": "goal", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "prompt_version": { + "name": "prompt_version", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "review_verdict": { + "name": "review_verdict", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "review": { + "name": "review", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_by": { + "name": "created_by", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "email_template_versions_campaign_idx": { + "name": "email_template_versions_campaign_idx", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "email_template_versions_campaign_version_uq": { + "name": "email_template_versions_campaign_version_uq", + "columns": [ + { + "expression": "campaign_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "version", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_email_template_versions_campaign_id_pdr_ai_v2_email_campaigns_id_fk": { + "name": "pdr_ai_v2_email_template_versions_campaign_id_pdr_ai_v2_email_campaigns_id_fk", + "tableFrom": "pdr_ai_v2_email_template_versions", + "tableTo": "pdr_ai_v2_email_campaigns", + "columnsFrom": [ + "campaign_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_repo_context_bundles": { + "name": "pdr_ai_v2_repo_context_bundles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "sha": { + "name": "sha", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "bundle": { + "name": "bundle", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "compute_ms": { + "name": "compute_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "repo_context_bundles_workspace_sha_unique": { + "name": "repo_context_bundles_workspace_sha_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_context_bundles_workspace_idx": { + "name": "repo_context_bundles_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_repo_context_bundles_workspace_id_pdr_ai_v2_repo_workspaces_id_fk": { + "name": "pdr_ai_v2_repo_context_bundles_workspace_id_pdr_ai_v2_repo_workspaces_id_fk", + "tableFrom": "pdr_ai_v2_repo_context_bundles", + "tableTo": "pdr_ai_v2_repo_workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_repo_explainer_jobs": { + "name": "pdr_ai_v2_repo_explainer_jobs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "diagram_type": { + "name": "diagram_type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "instructions": { + "name": "instructions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sha": { + "name": "sha", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "claim_id": { + "name": "claim_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "result": { + "name": "result", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "published_document_id": { + "name": "published_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "stale_at": { + "name": "stale_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "repo_explainer_jobs_company_idx": { + "name": "repo_explainer_jobs_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_explainer_jobs_workspace_idx": { + "name": "repo_explainer_jobs_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_explainer_jobs_status_idx": { + "name": "repo_explainer_jobs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_repo_explainer_jobs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_repo_explainer_jobs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_repo_explainer_jobs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_repo_explainer_jobs_workspace_id_pdr_ai_v2_repo_workspaces_id_fk": { + "name": "pdr_ai_v2_repo_explainer_jobs_workspace_id_pdr_ai_v2_repo_workspaces_id_fk", + "tableFrom": "pdr_ai_v2_repo_explainer_jobs", + "tableTo": "pdr_ai_v2_repo_workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_repo_sync_requests": { + "name": "pdr_ai_v2_repo_sync_requests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "workspace_id": { + "name": "workspace_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "reason": { + "name": "reason", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "claim_id": { + "name": "claim_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "requested_at": { + "name": "requested_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "repo_sync_requests_pending_unique": { + "name": "repo_sync_requests_pending_unique", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"pdr_ai_v2_repo_sync_requests\".\"status\" = 'pending'", + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_sync_requests_workspace_idx": { + "name": "repo_sync_requests_workspace_idx", + "columns": [ + { + "expression": "workspace_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_sync_requests_status_idx": { + "name": "repo_sync_requests_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_repo_sync_requests_workspace_id_pdr_ai_v2_repo_workspaces_id_fk": { + "name": "pdr_ai_v2_repo_sync_requests_workspace_id_pdr_ai_v2_repo_workspaces_id_fk", + "tableFrom": "pdr_ai_v2_repo_sync_requests", + "tableTo": "pdr_ai_v2_repo_workspaces", + "columnsFrom": [ + "workspace_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_repo_workspaces": { + "name": "pdr_ai_v2_repo_workspaces", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "provider": { + "name": "provider", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'github'" + }, + "owner": { + "name": "owner", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "repo": { + "name": "repo", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "head_sha": { + "name": "head_sha", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "mirror_path": { + "name": "mirror_path", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "disk_bytes": { + "name": "disk_bytes", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "last_synced_at": { + "name": "last_synced_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_error_message": { + "name": "last_error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "repo_workspaces_company_repo_unique": { + "name": "repo_workspaces_company_repo_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "owner", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "repo", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_workspaces_company_id_idx": { + "name": "repo_workspaces_company_id_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "repo_workspaces_status_idx": { + "name": "repo_workspaces_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_repo_workspaces_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_repo_workspaces_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_repo_workspaces", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_deal_stage_history": { + "name": "pdr_ai_v2_deal_stage_history", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "relationship_id": { + "name": "relationship_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "stage": { + "name": "stage", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "entered_at": { + "name": "entered_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "exited_at": { + "name": "exited_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "deal_stage_history_relationship_idx": { + "name": "deal_stage_history_relationship_idx", + "columns": [ + { + "expression": "relationship_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "entered_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "deal_stage_history_company_stage_idx": { + "name": "deal_stage_history_company_stage_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "deal_stage_history_one_open_unique": { + "name": "deal_stage_history_one_open_unique", + "columns": [ + { + "expression": "relationship_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"pdr_ai_v2_deal_stage_history\".\"exited_at\" is null", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_deal_stage_history_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_deal_stage_history_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_deal_stage_history", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_deal_stage_history_relationship_id_pdr_ai_v2_partner_relationships_id_fk": { + "name": "pdr_ai_v2_deal_stage_history_relationship_id_pdr_ai_v2_partner_relationships_id_fk", + "tableFrom": "pdr_ai_v2_deal_stage_history", + "tableTo": "pdr_ai_v2_partner_relationships", + "columnsFrom": [ + "relationship_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_distribution_agreements": { + "name": "pdr_ai_v2_distribution_agreements", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "relationship_id": { + "name": "relationship_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "territory": { + "name": "territory", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "exclusivity": { + "name": "exclusivity", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'none'" + }, + "starts_on": { + "name": "starts_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "ends_on": { + "name": "ends_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "terms": { + "name": "terms", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "renewal_reminder_at": { + "name": "renewal_reminder_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "distribution_agreements_relationship_idx": { + "name": "distribution_agreements_relationship_idx", + "columns": [ + { + "expression": "relationship_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "distribution_agreements_company_idx": { + "name": "distribution_agreements_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_distribution_agreements_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_distribution_agreements_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_distribution_agreements", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_distribution_agreements_relationship_id_pdr_ai_v2_partner_relationships_id_fk": { + "name": "pdr_ai_v2_distribution_agreements_relationship_id_pdr_ai_v2_partner_relationships_id_fk", + "tableFrom": "pdr_ai_v2_distribution_agreements", + "tableTo": "pdr_ai_v2_partner_relationships", + "columnsFrom": [ + "relationship_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_distribution_fit_verdicts": { + "name": "pdr_ai_v2_distribution_fit_verdicts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "program_id": { + "name": "program_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "resolve_key": { + "name": "resolve_key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fit": { + "name": "fit", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "basis": { + "name": "basis", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "segment_key": { + "name": "segment_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "judged_at": { + "name": "judged_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "distribution_fit_verdicts_program_org_unique": { + "name": "distribution_fit_verdicts_program_org_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "program_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resolve_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "distribution_fit_verdicts_company_idx": { + "name": "distribution_fit_verdicts_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "distribution_fit_verdicts_program_idx": { + "name": "distribution_fit_verdicts_program_idx", + "columns": [ + { + "expression": "program_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "judged_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_distribution_fit_verdicts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_distribution_fit_verdicts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_distribution_fit_verdicts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_distribution_fit_verdicts_program_id_pdr_ai_v2_distribution_programs_id_fk": { + "name": "pdr_ai_v2_distribution_fit_verdicts_program_id_pdr_ai_v2_distribution_programs_id_fk", + "tableFrom": "pdr_ai_v2_distribution_fit_verdicts", + "tableTo": "pdr_ai_v2_distribution_programs", + "columnsFrom": [ + "program_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_distribution_fit_verdicts_run_id_pdr_ai_v2_distribution_runs_id_fk": { + "name": "pdr_ai_v2_distribution_fit_verdicts_run_id_pdr_ai_v2_distribution_runs_id_fk", + "tableFrom": "pdr_ai_v2_distribution_fit_verdicts", + "tableTo": "pdr_ai_v2_distribution_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_distribution_programs": { + "name": "pdr_ai_v2_distribution_programs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "offering": { + "name": "offering", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "hs_codes": { + "name": "hs_codes", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "target_territories": { + "name": "target_territories", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "partner_kinds": { + "name": "partner_kinds", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "constraints": { + "name": "constraints", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "known_partner_domains": { + "name": "known_partner_domains", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'active'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "customer_domains": { + "name": "customer_domains", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + } + }, + "indexes": { + "distribution_programs_company_idx": { + "name": "distribution_programs_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_distribution_programs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_distribution_programs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_distribution_programs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_distribution_runs": { + "name": "pdr_ai_v2_distribution_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "program_id": { + "name": "program_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "options": { + "name": "options", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "plan": { + "name": "plan", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "summary": { + "name": "summary", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "candidate_org_ids": { + "name": "candidate_org_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "credits_used": { + "name": "credits_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "distribution_runs_company_idx": { + "name": "distribution_runs_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "distribution_runs_program_idx": { + "name": "distribution_runs_program_idx", + "columns": [ + { + "expression": "program_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "distribution_runs_company_status_idx": { + "name": "distribution_runs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_distribution_runs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_distribution_runs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_distribution_runs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_distribution_runs_program_id_pdr_ai_v2_distribution_programs_id_fk": { + "name": "pdr_ai_v2_distribution_runs_program_id_pdr_ai_v2_distribution_programs_id_fk", + "tableFrom": "pdr_ai_v2_distribution_runs", + "tableTo": "pdr_ai_v2_distribution_programs", + "columnsFrom": [ + "program_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_market_edges": { + "name": "pdr_ai_v2_market_edges", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "from_org_id": { + "name": "from_org_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "to_org_id": { + "name": "to_org_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "to_brand": { + "name": "to_brand", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "evidence_id": { + "name": "evidence_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "run_id": { + "name": "run_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "market_edges_company_idx": { + "name": "market_edges_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "market_edges_from_idx": { + "name": "market_edges_from_idx", + "columns": [ + { + "expression": "from_org_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "market_edges_brand_idx": { + "name": "market_edges_brand_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "to_brand", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_market_edges_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_market_edges_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_market_edges", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_market_edges_from_org_id_pdr_ai_v2_partner_orgs_id_fk": { + "name": "pdr_ai_v2_market_edges_from_org_id_pdr_ai_v2_partner_orgs_id_fk", + "tableFrom": "pdr_ai_v2_market_edges", + "tableTo": "pdr_ai_v2_partner_orgs", + "columnsFrom": [ + "from_org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_market_edges_to_org_id_pdr_ai_v2_partner_orgs_id_fk": { + "name": "pdr_ai_v2_market_edges_to_org_id_pdr_ai_v2_partner_orgs_id_fk", + "tableFrom": "pdr_ai_v2_market_edges", + "tableTo": "pdr_ai_v2_partner_orgs", + "columnsFrom": [ + "to_org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_market_edges_evidence_id_pdr_ai_v2_partner_evidence_id_fk": { + "name": "pdr_ai_v2_market_edges_evidence_id_pdr_ai_v2_partner_evidence_id_fk", + "tableFrom": "pdr_ai_v2_market_edges", + "tableTo": "pdr_ai_v2_partner_evidence", + "columnsFrom": [ + "evidence_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_partner_evidence": { + "name": "pdr_ai_v2_partner_evidence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "org_id": { + "name": "org_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "claim": { + "name": "claim", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source_url": { + "name": "source_url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "quote": { + "name": "quote", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "confidence": { + "name": "confidence", + "type": "real", + "primaryKey": false, + "notNull": true, + "default": 0.5 + }, + "captured_at": { + "name": "captured_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "provenance": { + "name": "provenance", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "partner_evidence_org_idx": { + "name": "partner_evidence_org_idx", + "columns": [ + { + "expression": "org_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_evidence_company_idx": { + "name": "partner_evidence_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_evidence_run_idx": { + "name": "partner_evidence_run_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_partner_evidence_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_partner_evidence_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_partner_evidence", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_partner_evidence_org_id_pdr_ai_v2_partner_orgs_id_fk": { + "name": "pdr_ai_v2_partner_evidence_org_id_pdr_ai_v2_partner_orgs_id_fk", + "tableFrom": "pdr_ai_v2_partner_evidence", + "tableTo": "pdr_ai_v2_partner_orgs", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_partner_evidence_run_id_pdr_ai_v2_distribution_runs_id_fk": { + "name": "pdr_ai_v2_partner_evidence_run_id_pdr_ai_v2_distribution_runs_id_fk", + "tableFrom": "pdr_ai_v2_partner_evidence", + "tableTo": "pdr_ai_v2_distribution_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_partner_orgs": { + "name": "pdr_ai_v2_partner_orgs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "resolve_key": { + "name": "resolve_key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "domain": { + "name": "domain", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "country": { + "name": "country", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "region": { + "name": "region", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "lat": { + "name": "lat", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "lng": { + "name": "lng", + "type": "double precision", + "primaryKey": false, + "notNull": false + }, + "roles": { + "name": "roles", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "size_band": { + "name": "size_band", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kg_entity_id": { + "name": "kg_entity_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "first_seen_run_id": { + "name": "first_seen_run_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "last_enriched_at": { + "name": "last_enriched_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "partner_orgs_company_resolve_key_unique": { + "name": "partner_orgs_company_resolve_key_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "resolve_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_orgs_company_idx": { + "name": "partner_orgs_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_orgs_domain_idx": { + "name": "partner_orgs_domain_idx", + "columns": [ + { + "expression": "domain", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_partner_orgs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_partner_orgs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_partner_orgs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_partner_relationships": { + "name": "pdr_ai_v2_partner_relationships", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(256)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "program_id": { + "name": "program_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "org_id": { + "name": "org_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "territory": { + "name": "territory", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "stage": { + "name": "stage", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'lead'" + }, + "fit_score": { + "name": "fit_score", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "fit_rationale": { + "name": "fit_rationale", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fit_breakdown": { + "name": "fit_breakdown", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "risk_flags": { + "name": "risk_flags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "screening": { + "name": "screening", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "dossier": { + "name": "dossier", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "owner_user_id": { + "name": "owner_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "next_action": { + "name": "next_action", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "next_action_at": { + "name": "next_action_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "last_activity_at": { + "name": "last_activity_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "dossier_document_id": { + "name": "dossier_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "source": { + "name": "source", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'discovery'" + }, + "stage_changed_at": { + "name": "stage_changed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "partner_relationships_program_org_kind_unique": { + "name": "partner_relationships_program_org_kind_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "program_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "org_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_relationships_company_idx": { + "name": "partner_relationships_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_relationships_program_idx": { + "name": "partner_relationships_program_idx", + "columns": [ + { + "expression": "program_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "partner_relationships_stage_idx": { + "name": "partner_relationships_stage_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "stage", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_partner_relationships_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_partner_relationships_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_partner_relationships", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_partner_relationships_program_id_pdr_ai_v2_distribution_programs_id_fk": { + "name": "pdr_ai_v2_partner_relationships_program_id_pdr_ai_v2_distribution_programs_id_fk", + "tableFrom": "pdr_ai_v2_partner_relationships", + "tableTo": "pdr_ai_v2_distribution_programs", + "columnsFrom": [ + "program_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_partner_relationships_org_id_pdr_ai_v2_partner_orgs_id_fk": { + "name": "pdr_ai_v2_partner_relationships_org_id_pdr_ai_v2_partner_orgs_id_fk", + "tableFrom": "pdr_ai_v2_partner_relationships", + "tableTo": "pdr_ai_v2_partner_orgs", + "columnsFrom": [ + "org_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_relationship_events": { + "name": "pdr_ai_v2_relationship_events", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigserial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "relationship_id": { + "name": "relationship_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "payload": { + "name": "payload", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "actor_user_id": { + "name": "actor_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "ref": { + "name": "ref", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "occurred_at": { + "name": "occurred_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "relationship_events_relationship_idx": { + "name": "relationship_events_relationship_idx", + "columns": [ + { + "expression": "relationship_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "relationship_events_company_idx": { + "name": "relationship_events_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_relationship_events_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_relationship_events_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_relationship_events", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_relationship_events_relationship_id_pdr_ai_v2_partner_relationships_id_fk": { + "name": "pdr_ai_v2_relationship_events_relationship_id_pdr_ai_v2_partner_relationships_id_fk", + "tableFrom": "pdr_ai_v2_relationship_events", + "tableTo": "pdr_ai_v2_partner_relationships", + "columnsFrom": [ + "relationship_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_agenda_topics": { + "name": "pdr_ai_v2_vantage_agenda_topics", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "agenda_id": { + "name": "agenda_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true, + "default": "'suggested'" + }, + "origin": { + "name": "origin", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "facts": { + "name": "facts", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "why_it_matters": { + "name": "why_it_matters", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "decision_question": { + "name": "decision_question", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "proposed_next_step": { + "name": "proposed_next_step", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "proposed_owner": { + "name": "proposed_owner", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "proposed_due": { + "name": "proposed_due", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "help_requested": { + "name": "help_requested", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "unknowns": { + "name": "unknowns", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "conflicts": { + "name": "conflicts", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "rationale": { + "name": "rationale", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared": { + "name": "shared", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "decision": { + "name": "decision", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "vantage_agenda_topics_agenda_position_idx": { + "name": "vantage_agenda_topics_agenda_position_idx", + "columns": [ + { + "expression": "agenda_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "vantage_agenda_topics_company_shared_idx": { + "name": "vantage_agenda_topics_company_shared_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "shared", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_agenda_topics_agenda_id_pdr_ai_v2_vantage_agendas_id_fk": { + "name": "pdr_ai_v2_vantage_agenda_topics_agenda_id_pdr_ai_v2_vantage_agendas_id_fk", + "tableFrom": "pdr_ai_v2_vantage_agenda_topics", + "tableTo": "pdr_ai_v2_vantage_agendas", + "columnsFrom": [ + "agenda_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_vantage_agenda_topics_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_agenda_topics_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_agenda_topics", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_agendas": { + "name": "pdr_ai_v2_vantage_agendas", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "week_start": { + "name": "week_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "signals": { + "name": "signals", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "model_metadata": { + "name": "model_metadata", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "generated_at": { + "name": "generated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "held_at": { + "name": "held_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "vantage_agendas_company_week_unique": { + "name": "vantage_agendas_company_week_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "week_start", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "vantage_agendas_company_created_idx": { + "name": "vantage_agendas_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_agendas_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_agendas_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_agendas", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_commitments": { + "name": "pdr_ai_v2_vantage_commitments", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "agenda_id": { + "name": "agenda_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "topic_id": { + "name": "topic_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "owner": { + "name": "owner", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "due_on": { + "name": "due_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "test": { + "name": "test", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "outcome": { + "name": "outcome", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared": { + "name": "shared", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "resolved_at": { + "name": "resolved_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "vantage_commitments_company_status_due_idx": { + "name": "vantage_commitments_company_status_due_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "vantage_commitments_agenda_idx": { + "name": "vantage_commitments_agenda_idx", + "columns": [ + { + "expression": "agenda_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_commitments_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_commitments_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_commitments", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_vantage_commitments_agenda_id_pdr_ai_v2_vantage_agendas_id_fk": { + "name": "pdr_ai_v2_vantage_commitments_agenda_id_pdr_ai_v2_vantage_agendas_id_fk", + "tableFrom": "pdr_ai_v2_vantage_commitments", + "tableTo": "pdr_ai_v2_vantage_agendas", + "columnsFrom": [ + "agenda_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "pdr_ai_v2_vantage_commitments_topic_id_pdr_ai_v2_vantage_agenda_topics_id_fk": { + "name": "pdr_ai_v2_vantage_commitments_topic_id_pdr_ai_v2_vantage_agenda_topics_id_fk", + "tableFrom": "pdr_ai_v2_vantage_commitments", + "tableTo": "pdr_ai_v2_vantage_agenda_topics", + "columnsFrom": [ + "topic_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_evidence": { + "name": "pdr_ai_v2_vantage_evidence", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar(300)", + "primaryKey": false, + "notNull": false + }, + "source_url": { + "name": "source_url", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false + }, + "observed_at": { + "name": "observed_at", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "default": "'private'" + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "vantage_evidence_company_observed_idx": { + "name": "vantage_evidence_company_observed_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "observed_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "vantage_evidence_company_kind_idx": { + "name": "vantage_evidence_company_kind_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_evidence_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_evidence_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_evidence", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_metric_definitions": { + "name": "pdr_ai_v2_vantage_metric_definitions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(120)", + "primaryKey": false, + "notNull": true + }, + "definition": { + "name": "definition", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "unit": { + "name": "unit", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "default": "'count'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "vantage_metric_definitions_company_key_unique": { + "name": "vantage_metric_definitions_company_key_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_metric_definitions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_metric_definitions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_metric_definitions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_metric_observations": { + "name": "pdr_ai_v2_vantage_metric_observations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "metric_id": { + "name": "metric_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "double precision", + "primaryKey": false, + "notNull": true + }, + "period_start": { + "name": "period_start", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "period_end": { + "name": "period_end", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar(300)", + "primaryKey": false, + "notNull": false + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "vantage_metric_observations_company_metric_period_idx": { + "name": "vantage_metric_observations_company_metric_period_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "metric_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "period_end", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_metric_observations_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_metric_observations_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_metric_observations", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_vantage_metric_observations_metric_id_pdr_ai_v2_vantage_metric_definitions_id_fk": { + "name": "pdr_ai_v2_vantage_metric_observations_metric_id_pdr_ai_v2_vantage_metric_definitions_id_fk", + "tableFrom": "pdr_ai_v2_vantage_metric_observations", + "tableTo": "pdr_ai_v2_vantage_metric_definitions", + "columnsFrom": [ + "metric_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_vantage_program_deadlines": { + "name": "pdr_ai_v2_vantage_program_deadlines", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(300)", + "primaryKey": false, + "notNull": true + }, + "due_on": { + "name": "due_on", + "type": "date", + "primaryKey": false, + "notNull": true + }, + "note": { + "name": "note", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "vantage_program_deadlines_company_due_idx": { + "name": "vantage_program_deadlines_company_due_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "due_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_vantage_program_deadlines_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_vantage_program_deadlines_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_vantage_program_deadlines", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_proposal_applications": { + "name": "pdr_ai_v2_proposal_applications", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "opportunity_id": { + "name": "opportunity_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "title": { + "name": "title", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "funder": { + "name": "funder", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "default": "'draft'" + }, + "deadline": { + "name": "deadline", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "owner_user_id": { + "name": "owner_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "request_text": { + "name": "request_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_url": { + "name": "request_url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "request_document_id": { + "name": "request_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "extracted": { + "name": "extracted", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "requirements": { + "name": "requirements", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "review": { + "name": "review", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "readiness": { + "name": "readiness", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "exported_document_id": { + "name": "exported_document_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "submitted_at": { + "name": "submitted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proposal_applications_company_status_idx": { + "name": "proposal_applications_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proposal_applications_company_deadline_idx": { + "name": "proposal_applications_company_deadline_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "deadline", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_proposal_applications_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_proposal_applications_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_proposal_applications", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_proposal_applications_opportunity_id_pdr_ai_v2_proposal_opportunities_id_fk": { + "name": "pdr_ai_v2_proposal_applications_opportunity_id_pdr_ai_v2_proposal_opportunities_id_fk", + "tableFrom": "pdr_ai_v2_proposal_applications", + "tableTo": "pdr_ai_v2_proposal_opportunities", + "columnsFrom": [ + "opportunity_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_proposal_library_items": { + "name": "pdr_ai_v2_proposal_library_items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "answer": { + "name": "answer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "evidence": { + "name": "evidence", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "source_application_id": { + "name": "source_application_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "source_section_key": { + "name": "source_section_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "uses": { + "name": "uses", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proposal_library_items_company_idx": { + "name": "proposal_library_items_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_proposal_library_items_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_proposal_library_items_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_proposal_library_items", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_proposal_library_items_source_application_id_pdr_ai_v2_proposal_applications_id_fk": { + "name": "pdr_ai_v2_proposal_library_items_source_application_id_pdr_ai_v2_proposal_applications_id_fk", + "tableFrom": "pdr_ai_v2_proposal_library_items", + "tableTo": "pdr_ai_v2_proposal_applications", + "columnsFrom": [ + "source_application_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_proposal_opportunities": { + "name": "pdr_ai_v2_proposal_opportunities", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "source": { + "name": "source", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "external_id": { + "name": "external_id", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "funder": { + "name": "funder", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "opens_on": { + "name": "opens_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "closes_on": { + "name": "closes_on", + "type": "date", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'candidate'" + }, + "amount_min": { + "name": "amount_min", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "amount_max": { + "name": "amount_max", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "eligibility": { + "name": "eligibility", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "categories": { + "name": "categories", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "fit": { + "name": "fit", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "run_id": { + "name": "run_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proposal_opportunities_company_source_external_unique": { + "name": "proposal_opportunities_company_source_external_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "source", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "external_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proposal_opportunities_company_status_idx": { + "name": "proposal_opportunities_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proposal_opportunities_company_closes_idx": { + "name": "proposal_opportunities_company_closes_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "closes_on", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_proposal_opportunities_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_proposal_opportunities_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_proposal_opportunities", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_proposal_runs": { + "name": "pdr_ai_v2_proposal_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "application_id": { + "name": "application_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "steps": { + "name": "steps", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "summary": { + "name": "summary", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "credits_used": { + "name": "credits_used", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "completed_at": { + "name": "completed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proposal_runs_company_created_idx": { + "name": "proposal_runs_company_created_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proposal_runs_company_status_idx": { + "name": "proposal_runs_company_status_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proposal_runs_application_idx": { + "name": "proposal_runs_application_idx", + "columns": [ + { + "expression": "application_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_proposal_runs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_proposal_runs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_proposal_runs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_proposal_runs_application_id_pdr_ai_v2_proposal_applications_id_fk": { + "name": "pdr_ai_v2_proposal_runs_application_id_pdr_ai_v2_proposal_applications_id_fk", + "tableFrom": "pdr_ai_v2_proposal_runs", + "tableTo": "pdr_ai_v2_proposal_applications", + "columnsFrom": [ + "application_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_proposal_sections": { + "name": "pdr_ai_v2_proposal_sections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "application_id": { + "name": "application_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "key": { + "name": "key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "guidance": { + "name": "guidance", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "word_limit": { + "name": "word_limit", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "required": { + "name": "required", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'empty'" + }, + "draft": { + "name": "draft", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "draft_meta": { + "name": "draft_meta", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "proposal_sections_application_position_idx": { + "name": "proposal_sections_application_position_idx", + "columns": [ + { + "expression": "application_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "position", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "proposal_sections_company_idx": { + "name": "proposal_sections_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_proposal_sections_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_proposal_sections_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_proposal_sections", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_proposal_sections_application_id_pdr_ai_v2_proposal_applications_id_fk": { + "name": "pdr_ai_v2_proposal_sections_application_id_pdr_ai_v2_proposal_applications_id_fk", + "tableFrom": "pdr_ai_v2_proposal_sections", + "tableTo": "pdr_ai_v2_proposal_applications", + "columnsFrom": [ + "application_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_actor_contexts": { + "name": "pdr_ai_v2_scenario_actor_contexts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "slot_id": { + "name": "slot_id", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "context": { + "name": "context", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "context_hash": { + "name": "context_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_actor_contexts_run_slot_unique": { + "name": "scenario_actor_contexts_run_slot_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "slot_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_actor_contexts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_actor_contexts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_actor_contexts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_actor_contexts_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_actor_contexts_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_actor_contexts", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_call_attempts": { + "name": "pdr_ai_v2_scenario_call_attempts", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "call_id": { + "name": "call_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "attempt": { + "name": "attempt", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "provider_request_id": { + "name": "provider_request_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "model": { + "name": "model", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false + }, + "raw_text": { + "name": "raw_text", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "input_tokens": { + "name": "input_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "output_tokens": { + "name": "output_tokens", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "latency_ms": { + "name": "latency_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "scenario_call_attempts_call_attempt_unique": { + "name": "scenario_call_attempts_call_attempt_unique", + "columns": [ + { + "expression": "call_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "attempt", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_call_attempts_started_idx": { + "name": "scenario_call_attempts_started_idx", + "columns": [ + { + "expression": "started_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_call_attempts_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_call_attempts_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_call_attempts", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_call_attempts_call_id_pdr_ai_v2_scenario_calls_id_fk": { + "name": "pdr_ai_v2_scenario_call_attempts_call_id_pdr_ai_v2_scenario_calls_id_fk", + "tableFrom": "pdr_ai_v2_scenario_call_attempts", + "tableTo": "pdr_ai_v2_scenario_calls", + "columnsFrom": [ + "call_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_calls": { + "name": "pdr_ai_v2_scenario_calls", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "unit_key": { + "name": "unit_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "logical_key": { + "name": "logical_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "request_hash": { + "name": "request_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "purpose": { + "name": "purpose", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true + }, + "actor_id": { + "name": "actor_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false + }, + "round": { + "name": "round", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "accepted_attempt_id": { + "name": "accepted_attempt_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_calls_logical_unique": { + "name": "scenario_calls_logical_unique", + "columns": [ + { + "expression": "logical_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_calls_run_unit_idx": { + "name": "scenario_calls_run_unit_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "unit_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_calls_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_calls_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_calls", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_calls_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_calls_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_calls", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_checkpoints": { + "name": "pdr_ai_v2_scenario_checkpoints", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "round": { + "name": "round", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "state_hash": { + "name": "state_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "engine_version": { + "name": "engine_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "turns": { + "name": "turns", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "interventions": { + "name": "interventions", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "skipped": { + "name": "skipped", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "degraded": { + "name": "degraded", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_checkpoints_run_round_unique": { + "name": "scenario_checkpoints_run_round_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "round", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_checkpoints_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_checkpoints_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_checkpoints", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_checkpoints_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_checkpoints_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_checkpoints", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_credit_reservations": { + "name": "pdr_ai_v2_scenario_credit_reservations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "unit_key": { + "name": "unit_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "settlement_key": { + "name": "settlement_key", + "type": "varchar(160)", + "primaryKey": false, + "notNull": true + }, + "reserved": { + "name": "reserved", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "settled": { + "name": "settled", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'held'" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "closed_at": { + "name": "closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "scenario_credit_reservations_key_unique": { + "name": "scenario_credit_reservations_key_unique", + "columns": [ + { + "expression": "settlement_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_credit_reservations_run_idx": { + "name": "scenario_credit_reservations_run_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_credit_reservations_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_credit_reservations_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_credit_reservations", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_credit_reservations_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_credit_reservations_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_credit_reservations", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_dispatches": { + "name": "pdr_ai_v2_scenario_dispatches", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "event_id": { + "name": "event_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "next_attempt_at": { + "name": "next_attempt_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "last_error": { + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sent_at": { + "name": "sent_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_dispatches_event_unique": { + "name": "scenario_dispatches_event_unique", + "columns": [ + { + "expression": "event_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_dispatches_due_idx": { + "name": "scenario_dispatches_due_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_attempt_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_dispatches_run_idx": { + "name": "scenario_dispatches_run_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_dispatches_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_dispatches_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_dispatches", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_dispatches_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_dispatches_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_dispatches", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_graph_builds": { + "name": "pdr_ai_v2_scenario_graph_builds", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "build_key": { + "name": "build_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "group_id": { + "name": "group_id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "manifest_hash": { + "name": "manifest_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "ontology_hash": { + "name": "ontology_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "policy_version": { + "name": "policy_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "owner_run_id": { + "name": "owner_run_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "owner_epoch": { + "name": "owner_epoch", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "snapshot_id": { + "name": "snapshot_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "frozen_at": { + "name": "frozen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "scenario_graph_builds_company_key_unique": { + "name": "scenario_graph_builds_company_key_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "build_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_graph_builds_group_unique": { + "name": "scenario_graph_builds_group_unique", + "columns": [ + { + "expression": "group_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_graph_builds_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_graph_builds_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_graph_builds", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_graph_ingestions": { + "name": "pdr_ai_v2_scenario_graph_ingestions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "build_id": { + "name": "build_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "unit_key": { + "name": "unit_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "evidence_ids": { + "name": "evidence_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "episode_uuids": { + "name": "episode_uuids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "scenario_graph_ingestions_build_unit_unique": { + "name": "scenario_graph_ingestions_build_unit_unique", + "columns": [ + { + "expression": "build_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "unit_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_graph_ingestions_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_graph_ingestions_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_graph_ingestions", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_graph_ingestions_build_id_pdr_ai_v2_scenario_graph_builds_id_fk": { + "name": "pdr_ai_v2_scenario_graph_ingestions_build_id_pdr_ai_v2_scenario_graph_builds_id_fk", + "tableFrom": "pdr_ai_v2_scenario_graph_ingestions", + "tableTo": "pdr_ai_v2_scenario_graph_builds", + "columnsFrom": [ + "build_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_graph_snapshots": { + "name": "pdr_ai_v2_scenario_graph_snapshots", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "build_id": { + "name": "build_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "graph_hash": { + "name": "graph_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_graph_snapshots_build_unique": { + "name": "scenario_graph_snapshots_build_unique", + "columns": [ + { + "expression": "build_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_graph_snapshots_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_graph_snapshots_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_graph_snapshots", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_graph_snapshots_build_id_pdr_ai_v2_scenario_graph_builds_id_fk": { + "name": "pdr_ai_v2_scenario_graph_snapshots_build_id_pdr_ai_v2_scenario_graph_builds_id_fk", + "tableFrom": "pdr_ai_v2_scenario_graph_snapshots", + "tableTo": "pdr_ai_v2_scenario_graph_builds", + "columnsFrom": [ + "build_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_injections": { + "name": "pdr_ai_v2_scenario_injections", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "text": { + "name": "text", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "applied_round": { + "name": "applied_round", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_injections_run_idx": { + "name": "scenario_injections_run_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "applied_round", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_injections_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_injections_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_injections", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_injections_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_injections_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_injections", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_interviews": { + "name": "pdr_ai_v2_scenario_interviews", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "asked_by_user_id": { + "name": "asked_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "agent_id": { + "name": "agent_id", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "question": { + "name": "question", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "answer": { + "name": "answer", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_interviews_run_asker_idx": { + "name": "scenario_interviews_run_asker_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "asked_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_interviews_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_interviews_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_interviews", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_interviews_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_interviews_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_interviews", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_ontology_specs": { + "name": "pdr_ai_v2_scenario_ontology_specs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "request_spec_id": { + "name": "request_spec_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "schema": { + "name": "schema", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "source_manifest_hash": { + "name": "source_manifest_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "planner_prompt_version": { + "name": "planner_prompt_version", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "planner_model": { + "name": "planner_model", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "validation": { + "name": "validation", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "ontology_hash": { + "name": "ontology_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_ontology_specs_run_unique": { + "name": "scenario_ontology_specs_run_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_ontology_specs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_ontology_specs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_ontology_specs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_ontology_specs_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_ontology_specs_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_ontology_specs", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_ontology_specs_request_spec_id_pdr_ai_v2_scenario_request_specs_id_fk": { + "name": "pdr_ai_v2_scenario_ontology_specs_request_spec_id_pdr_ai_v2_scenario_request_specs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_ontology_specs", + "tableTo": "pdr_ai_v2_scenario_request_specs", + "columnsFrom": [ + "request_spec_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_post_links": { + "name": "pdr_ai_v2_scenario_post_links", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "brand_post_id": { + "name": "brand_post_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_post_links_post_unique": { + "name": "scenario_post_links_post_unique", + "columns": [ + { + "expression": "brand_post_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_post_links_company_idx": { + "name": "scenario_post_links_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_post_links_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_post_links_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_post_links", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_post_links_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_post_links_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_post_links", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_request_specs": { + "name": "pdr_ai_v2_scenario_request_specs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "idempotency_key": { + "name": "idempotency_key", + "type": "varchar(200)", + "primaryKey": false, + "notNull": false + }, + "payload_hash": { + "name": "payload_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "spec": { + "name": "spec", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "spec_hash": { + "name": "spec_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_request_specs_idempotency_unique": { + "name": "scenario_request_specs_idempotency_unique", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "idempotency_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_request_specs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_request_specs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_request_specs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_runs": { + "name": "pdr_ai_v2_scenario_runs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "subject": { + "name": "subject", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "step": { + "name": "step", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "agent_count": { + "name": "agent_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "round_count": { + "name": "round_count", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "seed": { + "name": "seed", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "sources": { + "name": "sources", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "evidence": { + "name": "evidence", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "brief": { + "name": "brief", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "world": { + "name": "world", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "report": { + "name": "report", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "reception": { + "name": "reception", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "estimate": { + "name": "estimate", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "usage": { + "name": "usage", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "draft": { + "name": "draft", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "draft_hash": { + "name": "draft_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared_at": { + "name": "shared_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancel_requested_at": { + "name": "cancel_requested_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "lease_until": { + "name": "lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "events_closed_at": { + "name": "events_closed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "contract_version": { + "name": "contract_version", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "request_spec_id": { + "name": "request_spec_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "world_spec_id": { + "name": "world_spec_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 1 + }, + "lease_owner": { + "name": "lease_owner", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "lease_epoch": { + "name": "lease_epoch", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "context_mode": { + "name": "context_mode", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false + }, + "flags": { + "name": "flags", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "scenario_runs_company_creator_idx": { + "name": "scenario_runs_company_creator_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_runs_company_kind_idx": { + "name": "scenario_runs_company_kind_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "kind", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_runs_status_idx": { + "name": "scenario_runs_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_runs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_runs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_runs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_source_manifests": { + "name": "pdr_ai_v2_scenario_source_manifests", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "manifest": { + "name": "manifest", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "manifest_hash": { + "name": "manifest_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "document_ids": { + "name": "document_ids", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_source_manifests_run_unique": { + "name": "scenario_source_manifests_run_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_source_manifests_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_source_manifests_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_source_manifests", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_source_manifests_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_source_manifests_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_source_manifests", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_units": { + "name": "pdr_ai_v2_scenario_units", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "unit_key": { + "name": "unit_key", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true + }, + "seq": { + "name": "seq", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "depends_on": { + "name": "depends_on", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "input": { + "name": "input", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "input_hash": { + "name": "input_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "max_credits": { + "name": "max_credits", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "output": { + "name": "output", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "usage": { + "name": "usage", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "credits": { + "name": "credits", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "committed_at": { + "name": "committed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "duration_ms": { + "name": "duration_ms", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_units_run_unit_unique": { + "name": "scenario_units_run_unit_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "unit_key", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "scenario_units_run_seq_idx": { + "name": "scenario_units_run_seq_idx", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "seq", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_units_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_units_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_units", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_units_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_units_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_units", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_scenario_world_specs": { + "name": "pdr_ai_v2_scenario_world_specs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "run_id": { + "name": "run_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "generation": { + "name": "generation", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "spec": { + "name": "spec", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "initial_world": { + "name": "initial_world", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "spec_hash": { + "name": "spec_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + } + }, + "indexes": { + "scenario_world_specs_run_unique": { + "name": "scenario_world_specs_run_unique", + "columns": [ + { + "expression": "run_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "generation", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_scenario_world_specs_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_scenario_world_specs_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_scenario_world_specs", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_scenario_world_specs_run_id_pdr_ai_v2_scenario_runs_id_fk": { + "name": "pdr_ai_v2_scenario_world_specs_run_id_pdr_ai_v2_scenario_runs_id_fk", + "tableFrom": "pdr_ai_v2_scenario_world_specs", + "tableTo": "pdr_ai_v2_scenario_runs", + "columnsFrom": [ + "run_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_extraction_rows": { + "name": "pdr_ai_v2_extraction_rows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "table_id": { + "name": "table_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_id": { + "name": "document_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "document_title": { + "name": "document_title", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "cells": { + "name": "cells", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "extraction_rows_table_document_unique": { + "name": "extraction_rows_table_document_unique", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "extraction_rows_table_status_idx": { + "name": "extraction_rows_table_status_idx", + "columns": [ + { + "expression": "table_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "extraction_rows_company_idx": { + "name": "extraction_rows_company_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "extraction_rows_document_idx": { + "name": "extraction_rows_document_idx", + "columns": [ + { + "expression": "document_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_extraction_rows_table_id_pdr_ai_v2_extraction_tables_id_fk": { + "name": "pdr_ai_v2_extraction_rows_table_id_pdr_ai_v2_extraction_tables_id_fk", + "tableFrom": "pdr_ai_v2_extraction_rows", + "tableTo": "pdr_ai_v2_extraction_tables", + "columnsFrom": [ + "table_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_extraction_rows_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_extraction_rows_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_extraction_rows", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pdr_ai_v2_extraction_rows_document_id_pdr_ai_v2_document_id_fk": { + "name": "pdr_ai_v2_extraction_rows_document_id_pdr_ai_v2_document_id_fk", + "tableFrom": "pdr_ai_v2_extraction_rows", + "tableTo": "pdr_ai_v2_document", + "columnsFrom": [ + "document_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_extraction_tables": { + "name": "pdr_ai_v2_extraction_tables", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "company_id": { + "name": "company_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_by_user_id": { + "name": "created_by_user_id", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "title": { + "name": "title", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true + }, + "fields": { + "name": "fields", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "usage": { + "name": "usage", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "error": { + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "shared_at": { + "name": "shared_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "cancel_requested_at": { + "name": "cancel_requested_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "lease_until": { + "name": "lease_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "finished_at": { + "name": "finished_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "extraction_tables_company_creator_idx": { + "name": "extraction_tables_company_creator_idx", + "columns": [ + { + "expression": "company_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_by_user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "extraction_tables_status_idx": { + "name": "extraction_tables_status_idx", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pdr_ai_v2_extraction_tables_company_id_pdr_ai_v2_company_id_fk": { + "name": "pdr_ai_v2_extraction_tables_company_id_pdr_ai_v2_company_id_fk", + "tableFrom": "pdr_ai_v2_extraction_tables", + "tableTo": "pdr_ai_v2_company", + "columnsFrom": [ + "company_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pdr_ai_v2_accelerator_programs": { + "name": "pdr_ai_v2_accelerator_programs", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": true, + "notNull": true + }, + "program": { + "name": "program", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "content_hash": { + "name": "content_hash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "CURRENT_TIMESTAMP" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/apps/web/drizzle/meta/_journal.json b/apps/web/drizzle/meta/_journal.json index 199bb7487..67d846136 100644 --- a/apps/web/drizzle/meta/_journal.json +++ b/apps/web/drizzle/meta/_journal.json @@ -407,6 +407,13 @@ "when": 1795244444741, "tag": "20261121070044_document_public_links", "breakpoints": true + }, + { + "idx": 58, + "version": "7", + "when": 1795534824902, + "tag": "20261124154024_distribution_fit_verdicts", + "breakpoints": true } ] } \ No newline at end of file diff --git a/apps/web/src/i18n/messages/en/growth.json b/apps/web/src/i18n/messages/en/growth.json index bd7596b07..b3e4bc2ff 100644 --- a/apps/web/src/i18n/messages/en/growth.json +++ b/apps/web/src/i18n/messages/en/growth.json @@ -1436,6 +1436,7 @@ "segment": "Segment confirmed", "sources": "Sources", "shortlist": "Shortlist", + "fitCheck": "Fit check", "profiles": "Profiles", "people": "People" }, @@ -1446,6 +1447,10 @@ "peopleLater": "arrives with people lookup", "found": "{count} found", "excluded": "{count} excluded", + "fitRead": "{checked} read, {rejected} turned away", + "fitStopped": "stopped after {checked} read", + "fitNotRun": "could not run", + "fitStartedFrom": "{count, plural, one {# earlier verdict} other {# earlier verdicts}}", "failedGrounding": "{count} failed grounding", "caps": "{count} candidates", "capsSample": "{count} candidates · sample data", diff --git a/apps/web/src/i18n/messages/zh-CN/growth.json b/apps/web/src/i18n/messages/zh-CN/growth.json index 1056a8d75..fcd01db15 100644 --- a/apps/web/src/i18n/messages/zh-CN/growth.json +++ b/apps/web/src/i18n/messages/zh-CN/growth.json @@ -1436,6 +1436,7 @@ "segment": "细分市场已确认", "sources": "来源", "shortlist": "入围名单", + "fitCheck": "匹配度检查", "profiles": "画像", "people": "联系人" }, @@ -1446,6 +1447,10 @@ "peopleLater": "将随联系人查找功能推出", "found": "找到 {count} 个", "excluded": "排除 {count} 个", + "fitRead": "已读 {checked} 家,排除 {rejected} 家", + "fitStopped": "已读 {checked} 家后中断", + "fitNotRun": "未能运行", + "fitStartedFrom": "此前 {count} 条判断", "failedGrounding": "{count} 个未通过依据核验", "caps": "{count} 个候选", "capsSample": "{count} 个候选 · 示例数据", diff --git a/apps/web/src/server/prospects/adapter.ts b/apps/web/src/server/prospects/adapter.ts index 91f488e55..db4e7bb44 100644 --- a/apps/web/src/server/prospects/adapter.ts +++ b/apps/web/src/server/prospects/adapter.ts @@ -33,6 +33,7 @@ import { type RelationshipRecord, type RelationshipStage, type RunRecord, + type RunSummary, type SourceCount, } from "@launchstack/pipelines/distribution/types"; import { normalizeDomain } from "@launchstack/tools/org-resolver"; @@ -1188,6 +1189,40 @@ export function toRunDto(run: RunRecord, progress: RunProgress | null = null): R const sourcesOk = summary?.sources.filter(s => s.status === "ok").length ?? 0; const sourcesRun = summary?.sources.filter(s => s.status !== "skipped").length ?? 0; const profileTotal = run.candidateOrgIds?.length ?? run.options.maxCandidates; + // What filling the shortlist cost: the companies the fit check read, and + // the verdicts the ranking already knew when it started. A check that broke + // off says so instead of showing a tick. Every text stays short: the run + // sheet is 460px wide and a row is one line. + const fitCheckStep = (fit: NonNullable): RunStep => { + const stopped = fit.incomplete === true; + return { + id: "fit-check", + label: "Fit check", + detail: !stopped + ? `${fit.checked} read, ${fit.rejected} turned away` + : fit.checked > 0 + ? `stopped after ${fit.checked} read` + : "could not run", + status: stopped ? "failed" : "done", + right: + fit.startedFrom > 0 + ? `${fit.startedFrom} earlier verdict${fit.startedFrom === 1 ? "" : "s"}` + : null, + labelCopy: stepLabel("fitCheck"), + detailCopy: !stopped + ? copy("growth.server.runs.fitRead", { + checked: n(fit.checked), + rejected: n(fit.rejected), + }) + : fit.checked > 0 + ? copy("growth.server.runs.fitStopped", { checked: n(fit.checked) }) + : copy("growth.server.runs.fitNotRun"), + rightCopy: + fit.startedFrom > 0 + ? copy("growth.server.runs.fitStartedFrom", { count: fit.startedFrom }) + : null, + }; + }; const steps: RunStep[] = [ { id: "segment", @@ -1231,6 +1266,7 @@ export function toRunDto(run: RunRecord, progress: RunProgress | null = null): R rightCopy: summary?.excluded ? copy("growth.server.runs.excluded", { count: n(summary.excluded) }) : null, + ...(summary?.fitCheck ? { children: [fitCheckStep(summary.fitCheck)] } : {}), }, { id: "profiles", diff --git a/docs/manual-testing-guide.md b/docs/manual-testing-guide.md index d8481f5b0..d7158aba5 100644 --- a/docs/manual-testing-guide.md +++ b/docs/manual-testing-guide.md @@ -294,9 +294,22 @@ the brief ("retailers that would buy, stock or resell …") and each company's own words are embedded, and a company must read more like that buyer than like business in general. With a chat model configured, the closest companies are then checked ("would this business buy this?") and a no takes -them off the shortlist. The run's warnings say how many were left out for -area, for meaning and by the fit check. Without an embedding model the run -matches by shared words and says so. +them off the shortlist. The check goes in rounds of ten: after each round the +ranking of everyone not checked yet is redone from the verdicts so far, and +the highest ranked go next, until the shortlist is full. Verdicts are kept, +one per company and segment, and the next run of the segment starts its +ranking from them and from your own decisions on its deals (qualified, +pursued or won is a yes; Not a fit is a no). The fit check's verdicts answer +one question: rewrite what the segment sells, who buys it or what rules a +company out, or move its area, and they start afresh; your own decisions +always count. The run sheet's Shortlist step has a Fit check row: how many +companies were read, how many were turned away and, from the second run on, +how many earlier verdicts the ranking started from. If the fit check fails +part-way the row says where it stopped, and the places it left open go to the +next companies by meaning, unchecked (a company named outside the area that +was never read stays out); the run's warnings say so. They also say how many +companies were left out for area, for meaning and by the fit check. Without an embedding model the run matches by shared words, checks in +the fixed order, and says so. The run's `caps` line and the Sources yield labels say which mode produced it ("OpenStreetMap" for keyless; "Sample …" for fixtures). There is no diff --git a/pipelines/experiments/company-search/README.md b/pipelines/experiments/company-search/README.md index b90d20a12..1e14d19c2 100644 --- a/pipelines/experiments/company-search/README.md +++ b/pipelines/experiments/company-search/README.md @@ -66,8 +66,8 @@ Sources, all free and keyless: Photon and the OpenStreetMap API, Overpass, the Norwegian company register (Brønnøysundregistrene), the YC company directory, and the public pages of company websites. E4 also needs a local Ollama with `nomic-embed-text` for embeddings. No paid search engine is called -anywhere, and no paid model by E1 to E4; the recording script of -`production-replay/` is the exception (see "Production replay" below). +anywhere, and no paid model by E1 to E4; the two recording scripts of +`production-replay/` are the exception (see "Production replay" below). How the recorder behaves towards those sources: @@ -174,16 +174,24 @@ bootstrap interval over seeds. ## Production replay `production-replay/` puts the benchmark's pools through the ranking code -Prospects runs, on the app's two built-in embedding models. Its README has -the numbers; in short: +Prospects runs, on the app's two built-in embedding models, beside today's +ranking through the same code. Its README has the numbers; in short: - **The brief's language (after E4).** The gap between an English and a Norwegian brief on Norwegian texts is the local model's: 25.0 against 58.5 good companies in 100 checks there, 88.3 against 88.5 on `gemini-embedding-001` and 74.5 against 69.9 on `text-embedding-3-large`. Prospects does not translate the brief. +- **The shortlist that learns (E4's `linucb`, built into Prospects).** Through + production's own loop it finds 80.7 good companies in 100 checks against + 59.2 on the local model, and about 15 more than today's ranking on the two + built-in models. A run fills a 25-place shortlist in about 33 fit + checks instead of 50 to 53; most of that is asking ten at a time. +- **Real fit-check verdicts.** One pool was judged in full by production's fit + check. It agrees with the register on 96.8% of the companies, and the learner + behaves on its verdicts as it does on the labels. It has its own runner (`production-replay/run.ts`); `run.ts` above replays E1 -to E4 only. Its recording script is the only paid call in this folder; it -needs record mode and a spend cap, and says what it will send before it sends -it. +to E4 only. Its two recording scripts are the only paid calls in this folder; +each needs record mode and a spend cap, and says what it will send before it +sends it. diff --git a/pipelines/experiments/company-search/e4-whom-to-check/README.md b/pipelines/experiments/company-search/e4-whom-to-check/README.md index 84f4caafe..911d42b74 100644 --- a/pipelines/experiments/company-search/e4-whom-to-check/README.md +++ b/pipelines/experiments/company-search/e4-whom-to-check/README.md @@ -196,7 +196,7 @@ No reported segment was run before these choices were written into `config.ts`. - **A check here always tells the truth.** In production the verdict comes from a chat model and then a person, and both are sometimes wrong. No label noise is simulated; a learner fed wrong verdicts would learn less. - **The headline condition was chosen after the first run was reviewed.** It is the less favourable one for the learners and nothing was re-tuned for it, but it was not the plan: the Norwegian-brief runs were made as a sensitivity check. - **No pool starts almost empty.** In every pool, under either set of briefs, today's first 25 checks hold more than 8 good companies on average, so the experiment does not show how a learner fares when the first batches bring back no positive at all. -- **The embedding model is the local nomic-embed-text**, weaker than a paid model, most of all on Norwegian text read against an English brief. A stronger model would lift today's ranking and leave the learners less to add. +- **The embedding model is the local nomic-embed-text**, weaker than a paid model, most of all on Norwegian text read against an English brief. A stronger model would lift today's ranking and leave the learners less to add. `../production-replay/` measured it: on the app's two built-in embedding models the learner built from `linucb` gains about 15 good companies in 100 checks, not 21.7, and the gap between an English and a Norwegian brief disappears. - **The briefs carry no seller profile and no partner kind.** Production appends both ("As: retailer." and "Seller: ..."); a real brief is longer and sits further from the buyers' own words. - **Production's gate is ignored.** Production drops every company whose relevance is not above zero before any check; the simulation lets a policy reach them. With every brief in the buyers' language the gate would keep 98% of the good companies; with English briefs on the Norwegian pools it would keep 79% over the seven pools and 11% of Bergen's dentists. - **Seven pools from two sources.** Hyper-parameters were picked on two other segments of the Y Combinator directory, so the four reported YC segments share that pool's companies (not its labels); the three register pools were never seen before the reported run. The overall intervals resample pools as well as seeds, but seven pools cannot stand for every segment a customer will write. diff --git a/pipelines/experiments/company-search/production-replay/README.md b/pipelines/experiments/company-search/production-replay/README.md index 2d9a148a9..b135b2ad8 100644 --- a/pipelines/experiments/company-search/production-replay/README.md +++ b/pipelines/experiments/company-search/production-replay/README.md @@ -1,12 +1,14 @@ # Production replay -E1 to E4 asked what could work. This folder asks what the code Prospects runs does: the benchmark's pools go through production's own ranking code (`pipelines/src/distribution/`), on the two embedding models built into the app (`packages/llm/src/embeddings/index-registry.ts`). +E1 to E4 asked what could work. This folder asks what the code Prospects runs does: the benchmark's pools go through production's own ranking code (`pipelines/src/distribution/`), on the two embedding models built into the app (`packages/llm/src/embeddings/index-registry.ts`), beside today's ranking through the same code. -| Replay | Question | Production code it runs | Result file | -| ------- | ----------------------------------------------------------------------------------- | ------------------------------------- | ---------------------------------------- | -| `brief` | On Norwegian company texts, does a Norwegian brief rank better than an English one? | `semanticRelevance` (today's ranking) | `results/production-brief-language.json` | +| Replay | Question | Production code it runs | Result file | +| ----------- | ------------------------------------------------------------------------------------------------ | ---------------------------------------------------- | ---------------------------------------- | +| `brief` | On Norwegian company texts, does a Norwegian brief rank better than an English one? | `semanticRelevance` (today's ranking) | `results/production-brief-language.json` | +| `shortlist` | Does a shortlist that learns from each verdict find more good companies per fit check? | `fillShortlist` and `createShortlistLearner` | `results/production-shortlist.json` | +| `verdicts` | Does it still, when a check answers what the real fit check said? And what do kept verdicts buy? | the same, over recorded verdicts of `createFitJudge` | `results/production-verdicts.json` | -The result file has one block per embedding model: +Every result file has one block per embedding model: | Model | What it is | | ----------------------------- | ---------------------------------------------------------------------------------------- | @@ -34,29 +36,86 @@ Good companies found in 100 checks by today's ranking, mean of the three Norwegi So Prospects does not translate the brief: on the models it runs on there is nothing to gain, and a translated brief would switch the zero-score rule off. The rule is left as it is; what it costs on the built-in models is the 5% to 15% of good companies above. +### The shortlist that learns (plan item 4): built + +Seven pools, each with a brief in its companies' language. "Today" is the fixed ranking through production's loop; the learner is `createShortlistLearner` picking every round of ten. + +| Embedding model | Today, found in 100 checks | Learner | Learner minus today | Pools better / worse | +| ----------------------------- | -------------------------- | ------- | ---------------------- | -------------------- | +| `nomic-embed-text` | 59.2 | 80.7 | +21.5 (+11.9 to +32.1) | 7 / 0 | +| `gemini-embedding-001@768` | 69.7 | 84.5 | +14.9 (+5.1 to +25.2) | 5 / 2 | +| `text-embedding-3-large@1536` | 67.0 | 82.5 | +15.5 (+6.5 to +23.4) | 5 / 2 | + +- **The local model's row is E4's.** Today's 59.2 is E4's figure to the decimal, and the production learner's 80.7 is E4's `linucb` (80.9) with two differences: it asks ten at a time instead of five, and it finds the main directions of the embeddings in 6 passes instead of 20. +- **On the built-in models the gain is smaller**, about 15 good companies in 100 checks, because their fixed ranking is better to begin with. The four pools that are worse are worse by 0.2 to 1.7 companies in 100 checks over the 20 seeds (over three seeds one of them is 3.3 behind); in each of them today's ranking already finds 80 to 98. +- **The first 25 checks are level.** Learner minus today after 25 checks: +1.4 (−0.5 to +3.5), +0.6 (−1.0 to +2.3) and +1.0 (−1.0 to +3.2). The gain comes from about the 50th check on: +8.0, +3.4 and +4.8 after 50, and +42.1, +34.5 and +34.6 after 200. +- **Filling a 25-place shortlist.** Checks production's loop makes before the shortlist is full: + +| Embedding model | Today | Today's order, ten at a time | Learner | +| ----------------------------- | ----- | ---------------------------- | ------- | +| `nomic-embed-text` | 53.4 | 41.9 | 32.9 | +| `gemini-embedding-001@768` | 50.0 | 34.9 | 33.0 | +| `text-embedding-3-large@1536` | 52.5 | 38.2 | 32.3 | + +Most of that saving is the round size, not the learning: today's first round asks about 50 companies whatever the first 25 answer. On the built-in models learning adds 2 to 6 checks on top. So at the default shortlist of 25 a run ends after about 33 checks, before the learner's lead has opened; the +15 in 100 checks is what a longer search gets, a larger shortlist or a pool where few companies fit. The number of model calls is about the same either way: three to four (the fit check makes one call per twenty companies, so today's round of fifty is three calls). + +### Real fit-check verdicts + +Every company of the drinks pool (1,422) was judged once by production's fit check for the breweries segment: `createFitJudge` unchanged, English brief, on the dev setup's fast route. + +- **The fit check and the register mostly agree.** It said yes to 225 companies; the register calls 233 good; 206 are both, 19 only the fit check's, 27 only the register's. They agree on 96.8% of the pool. +- **A verdict is stable.** 200 companies were asked about a second time in other batches: 3 verdicts changed. +- **The learner behaves on real verdicts as it does on labels.** A company counts as good when the fit check said yes: + +| Embedding model | Today, yes in 25 / 50 / 100 checks | Learner | At 100 checks, over seeds | +| ----------------------------- | ---------------------------------- | ------------------ | ------------------------- | +| `nomic-embed-text` | 9.6 / 22.2 / 36.7 | 15.7 / 38.3 / 84.7 | +48.0 (+46.7 to +49.2) | +| `gemini-embedding-001@768` | 24.6 / 47.0 / 91.9 | 24.0 / 47.9 / 95.3 | +3.4 (+2.8 to +4.1) | +| `text-embedding-3-large@1536` | 21.7 / 44.9 / 81.4 | 21.3 / 45.0 / 92.4 | +11.0 (+10.1 to +11.9) | + +Where today's ranking is poor (the local model reading Norwegian against an English brief) the verdicts rescue it. Where it is already good (`gemini-embedding-001`: 92 of the first 100 are a yes) there is little left to add, and the first 25 checks cost half a company. + +- **What kept verdicts buy.** The pool is split in two; a first run fills its shortlist on one half and keeps its verdicts (30 to 40 of them); a second run then meets the other half, companies it has never seen: + +| Embedding model | Second run | Yes in its first 10 / 25 checks | Checks to fill 25 places | +| ----------------------------- | ------------------------------ | ------------------------------- | ------------------------ | +| `nomic-embed-text` | today's ranking | 4.9 / 10.2 | 70.3 | +| | learner, starting from nothing | 4.4 / 15.9 | 38.1 | +| | learner, from kept verdicts | 9.6 / 23.9 | 30.0 | +| `gemini-embedding-001@768` | today's ranking | 10.0 / 24.4 | 50.0 | +| | learner, starting from nothing | 9.0 / 23.4 | 30.0 | +| | learner, from kept verdicts | 10.0 / 24.7 | 30.0 | +| `text-embedding-3-large@1536` | today's ranking | 8.3 / 22.2 | 50.0 | +| | learner, starting from nothing | 7.7 / 21.3 | 30.4 | +| | learner, from kept verdicts | 10.0 / 24.1 | 30.0 | + +With a poor ranking the kept verdicts make the second run's first round right from the start (+5.2 yes's in the first ten, 4.6 to 5.7). With a good ranking they give back the one or two companies in ten that a learner starting from nothing spends on looking around (+1.0 and +2.3). + ## Run it All commands from `pipelines/`. Replays are offline: recorded pools and cached vectors only. ```sh -# The local model (a few seconds). +# Both replays that need no recorded verdicts, on the local model (about 6 minutes). pnpm exec tsx experiments/company-search/production-replay/run.ts -# One of the built-in models. -pnpm exec tsx experiments/company-search/production-replay/run.ts brief --model=gemini-embedding-001@768 +# One replay, one model. +pnpm exec tsx experiments/company-search/production-replay/run.ts shortlist --model=gemini-embedding-001@768 pnpm exec tsx experiments/company-search/production-replay/run.ts brief --model=text-embedding-3-large@1536 +pnpm exec tsx experiments/company-search/production-replay/run.ts verdicts --model=nomic-embed-text -# The test: three seeds by default, all twenty (and a check against the result file) with the variable. +# The tests: three seeds by default, all twenty (and a check against the result files) with the variable. pnpm exec vitest run experiments/company-search/production-replay COMPANY_SEARCH_REPLAY_SEEDS=20 pnpm exec vitest run experiments/company-search/production-replay ``` -- A replay with all 20 seeds rewrites its model's block in the result file; two replays of the same recording write the same numbers. A run with fewer seeds (`--seeds=3`) prints its table and leaves the file alone. -- The recordings are not in git (see the folder's own README). Where they are absent, as in CI, the replay test is skipped and a small test checks the committed result file instead. +- A replay with all 20 seeds rewrites its model's block in the result file; two replays of the same recording write the same numbers. A run with fewer seeds (`--seeds=3`) prints its table and leaves the files alone. +- The recordings are not in git (see the folder's own README). Where they are absent, as in CI, the replay tests are skipped and a small test checks the committed result files instead. +- With all 20 seeds the `shortlist` replay takes about 8 minutes on a 768-dimension model and 15 to 30 on the 1,536-dimension one, depending on what else the machine is doing; the other two replays take under 3 minutes. The tests with all twenty seeds take about 35 minutes together. -## Record it (the paid step) +## Record it (the paid steps) -One script sends texts to a paid model. It refuses to send anything without `COMPANY_SEARCH_BENCH_MODE=record` and a `--cap-usd`, prints its estimate first, stops when it is over the cap, and never sends a text twice. +Two scripts send texts to a paid model. Both refuse to send anything without `COMPANY_SEARCH_BENCH_MODE=record` and a `--cap-usd`, print their estimate first, stop when it is over the cap, and never send a text twice. ```sh # Embeddings of the four pools, the briefs and the baseline. @@ -64,15 +123,24 @@ COMPANY_SEARCH_BENCH_MODE=record pnpm exec tsx experiments/company-search/produc --model=gemini-embedding-001@768 --cap-usd=0.3 --via=openrouter COMPANY_SEARCH_BENCH_MODE=record pnpm exec tsx experiments/company-search/production-replay/record.ts \ --model=text-embedding-3-large@1536 --cap-usd=0.3 + +# The real fit check on every company of one pool, and 200 of them a second time. +COMPANY_SEARCH_BENCH_MODE=record pnpm exec tsx experiments/company-search/production-replay/record-verdicts.ts \ + --segment=brreg-breweries --cap-usd=1 --again=200 ``` - **What leaves the machine:** company names and their own activity texts, as the pools hold them. No address, phone or email. Sole proprietorships are often named after their owner. - **Keys:** `GOOGLE_AI_API_KEY`, `EMBEDDING_API_KEY` or `OPENAI_API_KEY`, and `OPENROUTER_API_KEY`, from the environment. - **`--via=openrouter`:** Google's own endpoint takes 100 texts a minute on its free tier. OpenRouter serves the same model at the same list price; eight texts recorded on both endpoints came back identical (cosine 1.000000). -- **What the recording of 2026-11-26 cost:** $0.26 (1.86 million tokens over the two models, all four pools). +- **What the recording of 2026-11-26 cost:** embeddings $0.26 (1.86 million tokens over the two models), fit-check verdicts about $0.59 (82 calls). ## Limits -- **Three pools, one language pair.** The pools are Norwegian register entries and the briefs English and Norwegian; another language or another kind of text may behave differently. -- **The Norwegian briefs are E4's**, written by hand as a Norwegian seller would type them. A machine translation was not tried, since the hand-written one already gains nothing. -- **Labels are register codes**, as in E4: a company is good when the register files it under the segment's class. +- **The brief replay is three pools and one language pair.** The pools are Norwegian register entries and the briefs English and Norwegian; another language or another kind of text may behave differently. The Norwegian briefs are E4's, written by hand; a machine translation was not tried, since the hand-written one already gains nothing. +- **Labels are still directory tags and register codes** in the `shortlist` replay, as in E4, and only one pool has real verdicts. That pool is one where the fit check and the register agree on 96.8%; a segment where a verdict turns on what a listing does not say would teach the learner less. +- **The judge is one chat model**: the fast route of the committed `apps/web/config/chat-models.yaml`, through OpenRouter. A deployment whose chat routes point at another model may judge differently; none was called. +- **The real verdicts were recorded once**, in batches of twenty in pool order. The replay answers the same verdict whatever batch a company is asked about in; asked twice, 3 of 200 differed. +- **One pool, split in two, stands in for "a later run".** Both halves come from the same register query, so the second run's companies are as like the first run's as they can be. +- **The pools are far larger than a keyless run's.** A replayed run has 1,100 to 5,000 candidates. The keyless Prospects runs made in the app on 2026-11-26 found 8 places for their segment, of which the fit check read 5 or 6 in a single round: with that few there is nothing to rank, so no live run has re-ranked anything yet, and the learner changes nothing until discovery brings more. +- **The replay ranks every company of a pool; a run first drops those whose relevance is not above zero.** With that rule applied first (`run.ts shortlist --zero-score-rule` and `run.ts verdicts --zero-score-rule`, 20 seeds, no result file written), today's figures do not move, since nobody the rule drops is among the first 200 of the fixed ranking. The learner's lead in 100 checks over the seven pools becomes +21.3, +15.9 and +16.1 on the three models, against +21.5, +14.9 and +15.5 above. On the judged pool it becomes +42.7, +3.8 and +10.6, against +48.0, +3.4 and +11.0: the rule costs the local model there, because with an English brief it drops 40% of that pool's good companies before any check. The later-run table always ranks the whole half. +- **Nothing was re-tuned.** The learner's settings are E4's: it tuned two of them on its two development segments with the local model (the prior spread of the direction weights and the bonus) and fixed the others by design. One setting is not E4's: production finds the main directions in 6 passes where E4 makes 20. diff --git a/pipelines/experiments/company-search/production-replay/later-run.ts b/pipelines/experiments/company-search/production-replay/later-run.ts new file mode 100644 index 000000000..f19b3c9b7 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/later-run.ts @@ -0,0 +1,180 @@ +/** + * "A later run starts from the verdicts it kept", replayed on real fit-check + * verdicts. + * + * A pool is split in two at random. Run 1 works through the first half with + * production's loop and learner until its shortlist is full; every verdict it + * got is kept, as a run keeps them (src/distribution/db.ts). Run 2 then meets + * the other half, companies it has never seen, three ways: + * + * today the fixed ranking, production's loop as it was + * fresh the learner, starting from nothing + * seeded the learner, starting from run 1's kept verdicts + * + * What a check answers is the recorded verdict of production's fit check + * (verdicts.ts), and a company is good when that verdict was yes. + */ +import { + learnerOverFeatures, + shortlistFeatures, + type EarlierVerdict, +} from "../../../src/distribution/learn"; +import type { FitVerdict } from "../../../src/distribution/semantic"; +import { + fillShortlist, + type FillShortlistArgs, + type ShortlistCandidate, +} from "../../../src/distribution/shortlist"; +import { mean, round } from "../e4-whom-to-check/stats"; +import { bootstrapMean } from "../lib/stats"; +import { createRng, hashSeed } from "../lib/rng"; +import { SHORTLIST, type PreparedSegment } from "./shortlist-replay"; + +export const LATER_ARMS = ["today", "fresh", "seeded"] as const; +export type LaterArm = (typeof LATER_ARMS)[number]; + +const BUDGETS = [10, 25, 50] as const; +type Metric = "found10" | "found25" | "found50" | "spent"; + +export interface LaterRunSummary { + seeds: number; + /** Companies in each half. */ + half: number; + /** Verdicts run 1 kept, mean over seeds. */ + kept: number; + /** Run 2, mean over seeds: yes's in its first 10, 25 and 50 checks, and checks spent to fill 25 places. */ + arms: Record>; + /** Seeded minus fresh, paired by seed, with a 95% interval over seeds. */ + seededMinusFresh: Record; +} + +interface Outcome { + found: number[]; + spent: number; +} + +export async function runLaterRunReplay( + prepared: PreparedSegment, + seeds: readonly number[] +): Promise { + const { pool, relevance, vectors } = prepared; + const verdicts = prepared.reveals ?? prepared.labels; + const judge: FillShortlistArgs["judge"] = async batch => + new Map( + batch.map(c => [c.id, { fit: verdicts[Number(c.id)] === 1, reason: "" }]) + ); + /** A half in today's order: relevance, ties in the split's order. */ + const queueOf = (indexes: number[]): number[] => + indexes + .map((index, at) => ({ index, at })) + .sort((a, b) => relevance[b.index]! - relevance[a.index]! || a.at - b.at) + .map(entry => entry.index); + const candidates = (order: number[]): ShortlistCandidate[] => + order.map(i => ({ id: String(i), name: "", text: "" })); + + const runs = Object.fromEntries(LATER_ARMS.map(arm => [arm, [] as Outcome[]])) as Record< + LaterArm, + Outcome[] + >; + const kept: number[] = []; + let half = 0; + for (const seed of seeds) { + const shuffled = createRng(hashSeed(`${pool.spec.id}|later-run|${seed}`)).shuffle( + Array.from({ length: pool.size }, (_, i) => i) + ); + half = Math.floor(pool.size / 2); + const first = queueOf(shuffled.slice(0, half)); + const second = queueOf(shuffled.slice(half, 2 * half)); + + // Run 1: the learner from nothing, until its shortlist is full. + const one = await fillShortlist({ + queue: candidates(first), + wanted: SHORTLIST, + judge, + learner: learnerOverFeatures( + await shortlistFeatures({ + vectors: first.map(i => vectors[i]!), + relevance: first.map(i => relevance[i]!), + }) + ), + }); + const earlier: EarlierVerdict[] = one.checked.map(id => ({ + vector: vectors[Number(id)]!, + relevance: relevance[Number(id)]!, + good: verdicts[Number(id)] === 1, + })); + kept.push(earlier.length); + + // Run 2 on the other half. + const features = { + fresh: await shortlistFeatures({ + vectors: second.map(i => vectors[i]!), + relevance: second.map(i => relevance[i]!), + }), + seeded: await shortlistFeatures({ + vectors: second.map(i => vectors[i]!), + relevance: second.map(i => relevance[i]!), + earlier, + }), + }; + for (const arm of LATER_ARMS) { + const learnerFor = (): FillShortlistArgs["learner"] => + arm === "today" ? null : learnerOverFeatures(features[arm]); + const long = await fillShortlist({ + queue: candidates(second), + wanted: second.length + 1, + judge, + learner: learnerFor(), + maxChecks: Math.max(...BUDGETS), + }); + const found = BUDGETS.map( + budget => + long.checked.slice(0, budget).filter(id => verdicts[Number(id)] === 1).length + ); + const filled = await fillShortlist({ + queue: candidates(second), + wanted: SHORTLIST, + judge, + learner: learnerFor(), + }); + runs[arm].push({ found, spent: filled.checked.length }); + } + } + + const valuesOf = (arm: LaterArm, metric: Metric): number[] => + metric === "spent" + ? runs[arm].map(o => o.spent) + : runs[arm].map(o => o.found[BUDGETS.indexOf(Number(metric.slice(5)) as 10)]!); + const metrics: Metric[] = ["found10", "found25", "found50", "spent"]; + return { + seeds: seeds.length, + half, + kept: round(mean(kept), 1), + arms: Object.fromEntries( + LATER_ARMS.map(arm => [ + arm, + Object.fromEntries( + metrics.map(metric => [metric, round(mean(valuesOf(arm, metric)), 2)]) + ), + ]) + ) as LaterRunSummary["arms"], + seededMinusFresh: Object.fromEntries( + metrics.map(metric => { + const seeded = valuesOf("seeded", metric); + const fresh = valuesOf("fresh", metric); + const interval = bootstrapMean( + seeded.map((v, i) => v - fresh[i]!), + { resamples: 2_000, seed: 20261126 } + ); + return [ + metric, + { + mean: round(interval.mean, 2), + lo: round(interval.lo, 2), + hi: round(interval.hi, 2), + }, + ]; + }) + ) as LaterRunSummary["seededMinusFresh"], + }; +} diff --git a/pipelines/experiments/company-search/production-replay/record-verdicts.ts b/pipelines/experiments/company-search/production-replay/record-verdicts.ts new file mode 100644 index 000000000..c2304e1ed --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/record-verdicts.ts @@ -0,0 +1,195 @@ +/** + * The other paid step of the production replay: asks production's own fit + * check about every company of one pool and keeps the verdicts on disk + * (verdicts.ts), so the learning shortlist can be replayed over real verdicts + * for free afterwards. + * + * COMPANY_SEARCH_BENCH_MODE=record OPENROUTER_API_KEY=... pnpm exec tsx \ + * experiments/company-search/production-replay/record-verdicts.ts \ + * --segment=brreg-breweries --cap-usd=1 [--again=200] [--limit=20] + * + * The judge is src/distribution/judge.ts unchanged, on the fast route of + * apps/web/config/chat-models.yaml through OpenRouter (the dev setup). It + * sends nothing unless record mode is set and a spend cap is given, prints its + * estimate first and stops when the estimate is over the cap. A company that + * already has a verdict is never asked about again. `--again=N` asks about N + * companies a second time, in other batches, to see how stable a verdict is; + * `--limit=N` stops after the first N companies (a trial before the pool). + * What leaves the machine: company names and their own activity texts (no + * address, phone or email), to OpenRouter and the model's provider. + */ +import { readFileSync } from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +import { configureChatModels, createChatModelsConfig } from "@launchstack/llm"; + +import { createFitJudge } from "../../../src/distribution/judge"; +import { briefOf, segmentText, type BriefLanguage } from "../e4-whom-to-check/briefs"; +import { createRecorder, loadPool } from "../e4-whom-to-check/data"; +import { segmentById } from "../e4-whom-to-check/segments"; +import { defaultMode } from "../lib/recorder"; +import { createRng, hashSeed } from "../lib/rng"; +import { JUDGE_ID, readVerdicts, WHERE, writeVerdicts, type RecordedVerdicts } from "./verdicts"; + +/** OpenRouter's list price for the fast route's model on 2026-11-26, US dollars per million tokens. */ +const USD_PER_MTOK = { input: 0.825, output: 4.125 }; +/** Companies per model call: the judge's own batch size. */ +const BATCH = 20; +/** What one call carries besides the companies (instructions, brief, place), in tokens. */ +const CALL_OVERHEAD = 480; +/** A verdict in the answer: id, yes or no, one short sentence. */ +const TOKENS_PER_VERDICT = 50; + +const args = new Map( + process.argv.slice(2).map(arg => { + const [key, value] = arg.replace(/^--/, "").split("="); + return [key!, value ?? "true"] as const; + }) +); +const segmentId = args.get("segment"); +const capUsd = Number(args.get("cap-usd")); +const language = (args.get("brief") ?? "en") as BriefLanguage; +const againCount = Number(args.get("again") ?? 0); +if (!segmentId || !Number.isFinite(capUsd) || capUsd <= 0) { + console.error( + "Usage: record-verdicts.ts --segment= --cap-usd= [--brief=en|no] [--again=N]" + ); + process.exit(1); +} +if (defaultMode() !== "record") { + console.error("Not in record mode (COMPANY_SEARCH_BENCH_MODE=record): nothing was sent."); + process.exit(1); +} +const apiKey = process.env.OPENROUTER_API_KEY; +if (!apiKey) { + console.error("OPENROUTER_API_KEY is not set: nothing was sent."); + process.exit(1); +} +const where = WHERE[segmentId]; +if (!where) { + console.error(`No place is written down for ${segmentId} (verdicts.ts).`); + process.exit(1); +} + +const segment = segmentById(segmentId); +const pool = await loadPool(createRecorder("replay"), segment.pool); +const brief = briefOf(segmentText(segment, language)); +const recorded: RecordedVerdicts = readVerdicts(segmentId, language) ?? { + segment: segmentId, + briefLanguage: language, + judge: JUDGE_ID, + poolFingerprint: pool.fingerprint, + verdicts: {}, +}; +if (recorded.poolFingerprint !== pool.fingerprint) { + console.error("The pool changed since these verdicts were recorded: nothing was sent."); + process.exit(1); +} + +const limit = Number(args.get("limit") ?? Number.POSITIVE_INFINITY); +const missing = pool.texts + .map((_, i) => i) + .filter(i => !recorded.verdicts[String(i)]) + .slice(0, limit); +// A second opinion: a fixed draw of judged companies, shuffled into other batches. +const rng = createRng(hashSeed(`${segmentId}|again`)); +const again = + againCount > 0 + ? rng + .shuffle(pool.texts.map((_, i) => i)) + .slice(0, againCount) + .filter(i => !recorded.again?.[String(i)]) + : []; + +const ask = [...missing, ...again]; +const inputTokens = + Math.ceil(ask.length / BATCH) * CALL_OVERHEAD + + ask.reduce((sum, i) => sum + Math.ceil(Math.min(pool.texts[i]!.length, 2_000) / 3) + 10, 0); +const outputTokens = ask.length * TOKENS_PER_VERDICT; +const estimate = + (inputTokens / 1e6) * USD_PER_MTOK.input + (outputTokens / 1e6) * USD_PER_MTOK.output; +console.log( + `${segmentId}: ${pool.size} companies, ${missing.length} without a verdict, ${again.length} to ask again; about ${inputTokens} tokens in and ${outputTokens} out, about $${estimate.toFixed(2)}` +); +if (ask.length === 0) process.exit(0); +if (estimate > capUsd) { + console.error(`Over the cap of $${capUsd}: nothing was sent.`); + process.exit(1); +} + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +configureChatModels( + createChatModelsConfig({ + yaml: readFileSync( + path.resolve(HERE, "../../../../apps/web/config/chat-models.yaml"), + "utf8" + ), + endpoint: { baseUrl: "https://openrouter.ai/api/v1", apiKey }, + }) +); +const judge = createFitJudge(); + +/** OpenRouter's own count of what the key has spent, in dollars; null when it cannot be read. */ +async function keyUsage(): Promise { + try { + const response = await fetch("https://openrouter.ai/api/v1/key", { + headers: { Authorization: `Bearer ${apiKey}` }, + }); + const body = (await response.json()) as { data?: { usage?: number } }; + return typeof body.data?.usage === "number" ? body.data.usage : null; + } catch { + return null; + } +} + +const before = await keyUsage(); +const started = Date.now(); +let unanswered = 0; + +async function round(indexes: number[], into: "verdicts" | "again"): Promise { + const PARALLEL = 3; + const batches: number[][] = []; + for (let at = 0; at < indexes.length; at += BATCH) batches.push(indexes.slice(at, at + BATCH)); + for (let at = 0; at < batches.length; at += PARALLEL) { + const answers = await Promise.all( + batches.slice(at, at + PARALLEL).map(async batch => { + const verdicts = await judge({ + brief, + where: where!, + candidates: batch.map(i => ({ id: String(i), name: "", text: pool.texts[i]! })), + }); + return { batch, verdicts }; + }) + ); + for (const { batch, verdicts } of answers) { + for (const i of batch) { + const verdict = verdicts.get(String(i)); + if (!verdict) { + unanswered += 1; + continue; + } + if (into === "again") (recorded.again ??= {})[String(i)] = verdict; + else recorded.verdicts[String(i)] = verdict; + } + } + writeVerdicts(recorded); + const done = Math.min(batches.length, at + PARALLEL); + if (done % 12 === 0 || done === batches.length) + console.log( + ` ${into}: ${done} of ${batches.length} calls (${Math.round((Date.now() - started) / 1000)} s)` + ); + } +} + +await round(missing, "verdicts"); +await round(again, "again"); +const after = await keyUsage(); +const yes = Object.values(recorded.verdicts).filter(v => v.fit).length; +console.log( + `Recorded: ${Object.keys(recorded.verdicts).length} verdicts (${yes} yes), ${Object.keys(recorded.again ?? {}).length} second opinions, ${unanswered} not answered for.` +); +if (before !== null && after !== null) + console.log( + `OpenRouter counts $${(after - before).toFixed(4)} spent on this key while this ran (anything else using the key at the same time is in that figure).` + ); diff --git a/pipelines/experiments/company-search/production-replay/run.ts b/pipelines/experiments/company-search/production-replay/run.ts index 04aedfd3b..c017cae03 100644 --- a/pipelines/experiments/company-search/production-replay/run.ts +++ b/pipelines/experiments/company-search/production-replay/run.ts @@ -3,20 +3,29 @@ * ../results/production-*.json. Offline: recorded pools and cached vectors * only, never a model or a network call. * - * pnpm exec tsx experiments/company-search/production-replay/run.ts # the local model - * pnpm exec tsx experiments/company-search/production-replay/run.ts brief --model=gemini-embedding-001@768 + * pnpm exec tsx experiments/company-search/production-replay/run.ts # both replays, local model + * pnpm exec tsx experiments/company-search/production-replay/run.ts shortlist --model=gemini-embedding-001@768 * pnpm exec tsx experiments/company-search/production-replay/run.ts brief --seeds=3 + * pnpm exec tsx experiments/company-search/production-replay/run.ts shortlist --zero-score-rule * - * `brief`: an English brief beside a Norwegian one on the three Norwegian - * pools. `--model` is one of models.ts whose vectors are on this machine - * (record.ts records the paid ones); each model has its own block in the - * results file. A run with fewer than E4's twenty seeds prints its table and - * leaves the file alone. + * `shortlist`: the shortlist that learns from each verdict, beside today's + * ranking, on E4's seven pools. `brief`: an English brief beside a Norwegian + * one on the three Norwegian pools. `verdicts` (only when asked for): the + * shortlist replay on one pool whose checks answer what production's fit + * check really said (record-verdicts.ts records them). `--model` is one of + * models.ts whose vectors are on this machine (record.ts records the paid + * ones); each model has its own block in a results file. A run with fewer + * than E4's twenty seeds prints its table and leaves the files alone, and so + * does one with `--zero-score-rule`, which drops the companies a run would + * drop before ranking (relevance not above zero): the committed results rank + * every company of a pool, as E4 does. */ import { existsSync, readFileSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; +import { LEARNER_SETTINGS } from "../../../src/distribution/learn"; +import { JUDGE_POOL_FACTOR, LEARNING_ROUND } from "../../../src/distribution/shortlist"; import { SIMULATION } from "../e4-whom-to-check/config"; import { stringifyResults } from "../lib/json"; import { @@ -26,11 +35,20 @@ import { type BriefSummary, } from "./brief-language"; import { offlineEmbedder, REPLAY_MODELS, replayModel } from "./models"; +import { table, type ShortlistSummary } from "./shortlist-report"; +import { BUDGETS, CHECKS_CAP, SHORTLIST } from "./shortlist-replay"; +import { runShortlistReplay } from "./shortlist-run"; import { LOCAL_MODEL, recordingsPresent } from "./vectors"; +import { runVerdictReplay, verdictTable, type VerdictSummary } from "./verdict-replay"; +import { JUDGE_ID, readVerdicts, WHERE } from "./verdicts"; const HERE = path.dirname(fileURLToPath(import.meta.url)); const RESULTS = path.resolve(HERE, "..", "results"); +export const SHORTLIST_RESULTS = path.join(RESULTS, "production-shortlist.json"); export const BRIEF_RESULTS = path.join(RESULTS, "production-brief-language.json"); +export const VERDICT_RESULTS = path.join(RESULTS, "production-verdicts.json"); +/** The pool whose every company the real fit check was asked about. */ +export const JUDGED_SEGMENT = "brreg-breweries"; interface Results { experiment: string; @@ -39,13 +57,17 @@ interface Results { /** One block per embedding model the pools were replayed with. */ byEmbedding: Record; } +export type ShortlistResults = Results; export type BriefResults = Results; +export type VerdictResults = Results; function read(file: string): Results | null { if (!existsSync(file)) return null; return JSON.parse(readFileSync(file, "utf8")) as Results; } +export const readShortlistResults = (): ShortlistResults | null => read(SHORTLIST_RESULTS); export const readBriefResults = (): BriefResults | null => read(BRIEF_RESULTS); +export const readVerdictResults = (): VerdictResults | null => read(VERDICT_RESULTS); const INTERVALS = "95% percentile bootstrap, 2,000 resamples: over pools and then seeds, as in E4"; @@ -58,13 +80,33 @@ function merged( model: string, summary: Summary ): Record { - const all: Record = { - ...(previous?.byEmbedding ?? {}), - [model]: summary, - }; + const all: Record = { ...(previous?.byEmbedding ?? {}), [model]: summary }; return Object.fromEntries(REPLAY_MODELS.filter(m => m.id in all).map(m => [m.id, all[m.id]!])); } +function shortlistDesign(byEmbedding: Record): Record { + return { + code: "src/distribution/shortlist.ts (fillShortlist) and src/distribution/learn.ts (createShortlistLearner), as production runs them", + pools: "E4's seven reported segments, each with a brief in its companies' own language (E4's headline condition)", + check: "one check reveals one company's hidden label (directory tag or register code) and costs 1", + candidates: `a seed's ${SIMULATION.subsample * 100}% draw of the pool, in today's order: relevance, ties in the draw's order`, + arms: { + today: `the fixed ranking through production's loop: ${JUDGE_POOL_FACTOR} companies per open shortlist place each round`, + "today-in-rounds": `the fixed ranking asked ${LEARNING_ROUND} at a time, so the effect of the round size alone is visible`, + learner: `production's learner picks every round of ${LEARNING_ROUND}`, + }, + metrics: { + found: `good companies among the first ${BUDGETS.join(", ")} checks, with no shortlist to fill`, + checksTo25: `checks until the ${SHORTLIST}th good company was checked, capped at ${CHECKS_CAP}`, + spent: `checks production's loop makes before a ${SHORTLIST}-place shortlist is full, in whole rounds`, + rounds: "rounds of that run. The fit check makes one model call per twenty companies of a round: three for today's first round of fifty, one for a round of ten", + }, + learner: LEARNER_SETTINGS, + embeddingModels: embeddingModels(byEmbedding), + intervals: INTERVALS, + }; +} + function briefDesign(byEmbedding: Record): Record { return { code: "src/distribution/semantic.ts (semanticRelevance), as production runs it; companies are checked from the top of that ranking down, as production does", @@ -86,6 +128,27 @@ function briefDesign(byEmbedding: Record): Record): Record { + return { + code: "src/distribution/shortlist.ts (fillShortlist) and src/distribution/learn.ts (createShortlistLearner), as production runs them", + pool: `${JUDGED_SEGMENT}: every company judged once by production's fit check (src/distribution/judge.ts, unchanged), English brief, "${WHERE[JUDGED_SEGMENT]}" as the place`, + judge: `${JUDGE_ID}: the fast route of apps/web/config/chat-models.yaml through OpenRouter. A deployment whose chat routes point at another model may judge differently; none was called`, + check: "one check answers the recorded verdict on that company and costs 1; the loop and the learner see nothing else", + counted: { + judged: "a company is good when the fit check said yes", + register: "a company is good by its register code, as in E4", + }, + stability: + "200 companies were asked about a second time in other batches; `changed` is how many verdicts differ", + candidates: `a seed's ${SIMULATION.subsample * 100}% draw of the pool, in today's order`, + laterRun: + "the pool is split in two at random. A first run fills its shortlist on one half with the learner and keeps its verdicts; a second run meets the other half three ways: today's ranking, the learner starting from nothing (`fresh`), and the learner starting from the kept verdicts (`seeded`)", + embeddingModels: embeddingModels(byEmbedding), + intervals: + "95% percentile bootstrap over the seeds of this one pool: they say how stable the figure is on this pool, not how far it carries to another", + }; +} + async function main(): Promise { const positional = process.argv.slice(2).filter(arg => !arg.startsWith("--")); const args = new Map( @@ -97,11 +160,13 @@ async function main(): Promise { return [key!, value ?? "true"] as const; }) ); - const which = positional.length > 0 ? positional : ["brief"]; + const which = positional.length > 0 ? positional : ["brief", "shortlist"]; const model = replayModel(args.get("model") ?? LOCAL_MODEL); const seedCount = Number(args.get("seeds") ?? SIMULATION.seeds.length); const seeds = SIMULATION.seeds.slice(0, seedCount); - const full = seedCount === SIMULATION.seeds.length; + const zeroScoreRule = args.has("zero-score-rule") && args.get("zero-score-rule") !== "false"; + // Only the committed condition is written down: all twenty seeds, the whole pool ranked. + const full = seedCount === SIMULATION.seeds.length && !zeroScoreRule; if (!recordingsPresent(model.id)) { console.error( `The recorded pools or the ${model.id} vectors are not on this machine (COMPANY_SEARCH_BENCH_CACHE). Nothing to replay.` @@ -131,7 +196,60 @@ async function main(): Promise { progress(`wrote ${path.relative(process.cwd(), BRIEF_RESULTS)}`); } } - if (!full) console.log(`${seedCount} seeds: a partial run, results files left as they are.`); + if (which.includes("shortlist")) { + const { summary } = await runShortlistReplay({ + embedder: offlineEmbedder(model.id), + seeds, + zeroScoreRule, + onProgress: progress, + }); + console.log(`\n${model.id}\n${table(summary)}\n`); + if (full) { + const byEmbedding = merged(readShortlistResults(), model.id, summary); + const results: ShortlistResults = { + experiment: "production-replay: the shortlist learns from each verdict", + question: + "Does production's own ranking code find more good companies per fit check than today's fixed ranking, on E4's pools?", + design: shortlistDesign(byEmbedding), + byEmbedding, + }; + writeFileSync(SHORTLIST_RESULTS, stringifyResults(results)); + progress(`wrote ${path.relative(process.cwd(), SHORTLIST_RESULTS)}`); + } + } + if (which.includes("verdicts")) { + if (!readVerdicts(JUDGED_SEGMENT, "en")) { + console.error( + `No recorded fit-check verdicts for ${JUDGED_SEGMENT} on this machine: record-verdicts.ts records them (paid).` + ); + process.exit(1); + } + const summary = await runVerdictReplay({ + embedder: offlineEmbedder(model.id), + segment: JUDGED_SEGMENT, + seeds, + zeroScoreRule, + }); + console.log(`\n${verdictTable(model.id, summary)}\n`); + if (full) { + const byEmbedding = merged(readVerdictResults(), model.id, summary); + const results: VerdictResults = { + experiment: "production-replay: the learning shortlist on real fit-check verdicts", + question: + "When a check answers what production's fit check really said, does the learning shortlist still find more companies per check than today's ranking?", + design: verdictDesign(byEmbedding), + byEmbedding, + }; + writeFileSync(VERDICT_RESULTS, stringifyResults(results)); + progress(`wrote ${path.relative(process.cwd(), VERDICT_RESULTS)}`); + } + } + if (!full) + console.log( + zeroScoreRule + ? `${seedCount} seeds with the relevance-above-zero rule applied first: a variant, results files left as they are.` + : `${seedCount} seeds: a partial run, results files left as they are.` + ); } if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) diff --git a/pipelines/experiments/company-search/production-replay/shortlist-replay.ts b/pipelines/experiments/company-search/production-replay/shortlist-replay.ts new file mode 100644 index 000000000..7f638e10c --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/shortlist-replay.ts @@ -0,0 +1,197 @@ +/** + * "The shortlist learns from each verdict", replayed: the benchmark's pools + * (E4) go through production's own fit-check loop + * (src/distribution/shortlist.ts) and learner (src/distribution/learn.ts), + * beside today's fixed ranking through the same loop. + * + * A check here reveals a company's hidden label, as in E4: the judge port + * answers from the register code or the directory tag. No row leaves the + * cache: the loop sees ids, and the results are counts. + * + * Three ways of checking, per pool and seed: + * today the fixed ranking, production's loop as it was + * today-in-rounds the fixed ranking asked in the learner's small rounds, + * so what the round size alone changes is visible + * learner production's learner picks every round + */ +import { + learnerOverFeatures, + shortlistFeatures, + type LearnerSettings, + type ShortlistLearner, +} from "../../../src/distribution/learn"; +import { + semanticRelevance, + type EmbedTexts, + type FitVerdict, +} from "../../../src/distribution/semantic"; +import { + fillShortlist, + LEARNING_ROUND, + type FillShortlistArgs, + type ShortlistCandidate, +} from "../../../src/distribution/shortlist"; +import { briefOf, segmentText, type BriefLanguage } from "../e4-whom-to-check/briefs"; +import type { LoadedPool } from "../e4-whom-to-check/data"; +import type { Segment } from "../e4-whom-to-check/segments"; +import { subsampleOf } from "../e4-whom-to-check/simulate"; +import type { ReplayEmbedder } from "./vectors"; + +export const BUDGETS = [25, 50, 100, 200] as const; +/** Production's default shortlist size (RunOptions.maxCandidates). */ +export const SHORTLIST = 25; +/** As in E4: a run that has not found 25 good companies by here counts as this many checks. */ +export const CHECKS_CAP = 500; + +export const ARMS = ["today", "today-in-rounds", "learner"] as const; +export type Arm = (typeof ARMS)[number]; + +export interface SeedOutcome { + /** Good companies among the first b checks, per budget. */ + found: number[]; + /** Checks until the 25th good company was checked; the cap when it never was. */ + checksTo25: number; + /** Checks production's loop spent before a 25-place shortlist was full. */ + spent: number; + /** Rounds of that run (the fit check makes one model call per twenty companies of a round). */ + rounds: number; +} + +export interface PreparedSegment { + segment: Segment; + language: BriefLanguage; + pool: LoadedPool; + brief: string; + /** Production's semanticRelevance of every company in the pool to the brief. */ + relevance: number[]; + vectors: number[][]; + /** 1 where a company counts as good: what the results count. */ + labels: Uint8Array; + /** + * What a check answers, when that is not the label itself: a recorded + * fit-check verdict per company (verdict-replay.ts). The loop and the + * learner see only this. + */ + reveals?: Uint8Array; +} + +/** Everything about a (segment, brief) that does not depend on the seed. */ +export async function prepareSegment( + embedder: ReplayEmbedder, + pool: LoadedPool, + segment: Segment, + language: BriefLanguage +): Promise { + const brief = briefOf(segmentText(segment, language)); + const embed: EmbedTexts = texts => embedder.embed(texts); + return { + segment, + language, + pool, + brief, + relevance: await semanticRelevance(embed, brief, pool.texts), + vectors: await embedder.embed(pool.texts), + labels: pool.labels(segment.label), + }; +} + +/** The fixed order, behind the learner's interface: it picks the next ones down the list. */ +function fixedOrder(size: number): Pick { + let at = 0; + return { + next(count) { + const out = Array.from({ length: Math.min(count, size - at) }, (_, i) => at + i); + at += out.length; + return out; + }, + observe() { + /* a fixed order learns nothing */ + }, + skip() { + /* nor from a company nobody judged */ + }, + }; +} + +export interface ReplayOptions { + settings?: Partial; + roundSize?: number; + arms?: readonly Arm[]; + /** + * Drop the companies whose relevance is not above zero before anything is + * ranked, as a run does (src/distribution/run.ts). Off in the committed + * results, which rank every company of a pool as E4 does. + */ + zeroScoreRule?: boolean; +} + +/** + * One seed of one segment: the seed's 80% draw of the pool is the run's + * candidates, in today's order (relevance, ties in the draw's order). + */ +export async function replaySeed( + prepared: PreparedSegment, + seed: number, + options: ReplayOptions = {} +): Promise>> { + const { pool, relevance, vectors, labels } = prepared; + const reveals = prepared.reveals ?? labels; + const active = subsampleOf(pool.spec.id, pool.size, seed); + const order = Array.from({ length: active.length }, (_, a) => a) + .sort((a, b) => relevance[active[b]!]! - relevance[active[a]!]! || a - b) + .map(a => active[a]!) + .filter(i => !options.zeroScoreRule || relevance[i]! > 0); + const queue: ShortlistCandidate[] = order.map(i => ({ id: String(i), name: "", text: "" })); + const judge: FillShortlistArgs["judge"] = async batch => + new Map( + batch.map(c => [c.id, { fit: reveals[Number(c.id)] === 1, reason: "" }]) + ); + const roundSize = options.roundSize ?? LEARNING_ROUND; + + const features = (options.arms ?? ARMS).includes("learner") + ? await shortlistFeatures({ + vectors: order.map(i => vectors[i]!), + relevance: order.map(i => relevance[i]!), + settings: options.settings, + }) + : null; + const learnerFor = (arm: Arm): FillShortlistArgs["learner"] => + arm === "today" + ? null + : arm === "today-in-rounds" + ? fixedOrder(queue.length) + : learnerOverFeatures({ ...features!, settings: options.settings }); + + const out: Partial> = {}; + for (const arm of options.arms ?? ARMS) { + // How many good companies the first b checks find: the loop with no + // shortlist to fill, stopped at the cap. + const long = await fillShortlist({ + queue, + wanted: queue.length + 1, + judge, + learner: learnerFor(arm), + roundSize, + maxChecks: CHECKS_CAP, + }); + const found = BUDGETS.map(() => 0); + let good = 0; + let checksTo25 = CHECKS_CAP; + for (const [at, id] of long.checked.entries()) { + if (labels[Number(id)] !== 1) continue; + good += 1; + for (const [b, budget] of BUDGETS.entries()) if (at < budget) found[b]! += 1; + if (good === SHORTLIST) checksTo25 = Math.min(checksTo25, at + 1); + } + // What a run spends: production's loop until 25 places are full. + const run = await fillShortlist({ + queue, + wanted: SHORTLIST, + judge, + learner: learnerFor(arm), + roundSize, + }); + out[arm] = { found, checksTo25, spent: run.checked.length, rounds: run.rounds }; + } + return out; +} diff --git a/pipelines/experiments/company-search/production-replay/shortlist-report.ts b/pipelines/experiments/company-search/production-replay/shortlist-report.ts new file mode 100644 index 000000000..74280d319 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/shortlist-report.ts @@ -0,0 +1,148 @@ +/** + * From per-seed outcomes to the numbers a reader needs: per pool and overall, + * each way of checking beside today's, with intervals. + * + * Intervals are E4's: over seeds within a pool, and over pools and then seeds + * for the overall figures (../e4-whom-to-check/stats.ts says why). + */ +import { clustered, difference, mean, round, type Spread } from "../e4-whom-to-check/stats"; +import { ARMS, BUDGETS, type Arm, type SeedOutcome } from "./shortlist-replay"; + +export interface SegmentOutcomes { + segment: string; + pool: string; + briefLanguage: string; + /** Companies in a seed's draw. */ + candidates: number; + /** Good companies in the whole pool. */ + good: number; + /** [seed] per way of checking. */ + arms: Record; +} + +type Metric = "found25" | "found50" | "found100" | "found200" | "checksTo25" | "spent" | "rounds"; +const METRICS: Metric[] = [ + "found25", + "found50", + "found100", + "found200", + "checksTo25", + "spent", + "rounds", +]; + +function valuesOf(outcomes: readonly SeedOutcome[], metric: Metric): number[] { + if (metric === "checksTo25") return outcomes.map(o => o.checksTo25); + if (metric === "spent") return outcomes.map(o => o.spent); + if (metric === "rounds") return outcomes.map(o => o.rounds); + const at = BUDGETS.indexOf(Number(metric.slice(5)) as (typeof BUDGETS)[number]); + return outcomes.map(o => o.found[at]!); +} + +export interface ShortlistSummary { + seeds: number; + perSegment: Array<{ + segment: string; + pool: string; + briefLanguage: string; + candidates: number; + good: number; + /** Mean over seeds. */ + arms: Record>; + }>; + /** Mean of the segments' means, 95% interval over segments and seeds. */ + overall: Record>; + /** Each way of checking minus today's, paired by seed. */ + vsToday: Record, Record>; +} + +export function summarise(segments: readonly SegmentOutcomes[]): ShortlistSummary { + const digits = (metric: Metric): number => (metric === "rounds" ? 1 : 2); + const perSegment = segments.map(s => ({ + segment: s.segment, + pool: s.pool, + briefLanguage: s.briefLanguage, + candidates: s.candidates, + good: s.good, + arms: Object.fromEntries( + ARMS.map(arm => [ + arm, + Object.fromEntries( + METRICS.map(metric => [metric, round(mean(valuesOf(s.arms[arm], metric)), 2)]) + ), + ]) + ) as Record>, + })); + const overall = Object.fromEntries( + ARMS.map(arm => [ + arm, + Object.fromEntries( + METRICS.map(metric => [ + metric, + clustered( + segments.map(s => valuesOf(s.arms[arm], metric)), + digits(metric) + ), + ]) + ), + ]) + ) as ShortlistSummary["overall"]; + const vsToday = Object.fromEntries( + ARMS.filter(arm => arm !== "today").map(arm => [ + arm, + Object.fromEntries( + METRICS.map(metric => [ + metric, + clustered( + segments.map(s => + difference( + valuesOf(s.arms[arm], metric), + valuesOf(s.arms.today, metric) + ) + ), + digits(metric) + ), + ]) + ), + ]) + ) as ShortlistSummary["vsToday"]; + return { seeds: segments[0]?.arms.today.length ?? 0, perSegment, overall, vsToday }; +} + +const pad = (value: string | number, width: number): string => String(value).padStart(width); +const signed = (value: number): string => (value > 0 ? `+${value}` : String(value)); + +/** The table a run prints: today's ranking and the learner side by side. */ +export function table(summary: ShortlistSummary): string { + const lines: string[] = []; + lines.push( + `Good companies found in 100 checks, and checks a run spends to fill 25 places (${summary.seeds} seeds)` + ); + lines.push( + `${"segment".padEnd(22)}${pad("today", 8)}${pad("learner", 9)}${pad("gain", 8)} | spent: ${pad("today", 6)}${pad("in rounds", 11)}${pad("learner", 9)}` + ); + for (const s of summary.perSegment) { + const gain = round(s.arms.learner.found100 - s.arms.today.found100, 2); + lines.push( + `${s.segment.padEnd(22)}${pad(s.arms.today.found100, 8)}${pad(s.arms.learner.found100, 9)}${pad(signed(gain), 8)} | ${pad(s.arms.today.spent, 6)}${pad(s.arms["today-in-rounds"].spent, 11)}${pad(s.arms.learner.spent, 9)}` + ); + } + const o = summary.overall; + const d = summary.vsToday.learner; + lines.push( + `${"all segments".padEnd(22)}${pad(o.today.found100.mean, 8)}${pad(o.learner.found100.mean, 9)}${pad(signed(d.found100.mean), 8)} | ${pad(o.today.spent.mean, 6)}${pad(o["today-in-rounds"].spent.mean, 11)}${pad(o.learner.spent.mean, 9)}` + ); + lines.push( + `learner minus today, found in 100 checks: ${signed(d.found100.mean)} (95% interval ${signed(d.found100.lo)} to ${signed(d.found100.hi)})` + ); + lines.push( + `at 25 / 50 / 200 checks: ${signed(d.found25.mean)} (${signed(d.found25.lo)} to ${signed(d.found25.hi)}) / ${signed(d.found50.mean)} (${signed(d.found50.lo)} to ${signed(d.found50.hi)}) / ${signed(d.found200.mean)} (${signed(d.found200.lo)} to ${signed(d.found200.hi)})` + ); + lines.push( + `checks until the 25th good company: today ${o.today.checksTo25.mean}, learner ${o.learner.checksTo25.mean} (${signed(d.checksTo25.mean)}, ${signed(d.checksTo25.lo)} to ${signed(d.checksTo25.hi)})` + ); + lines.push( + `checks a run spends to fill 25 places: today ${o.today.spent.mean}, today in rounds ${o["today-in-rounds"].spent.mean}, learner ${o.learner.spent.mean}` + ); + return lines.join("\n"); +} diff --git a/pipelines/experiments/company-search/production-replay/shortlist-run.ts b/pipelines/experiments/company-search/production-replay/shortlist-run.ts new file mode 100644 index 000000000..e4b6f46d1 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/shortlist-run.ts @@ -0,0 +1,70 @@ +/** + * Runs the shortlist replay over E4's seven reported segments, each with a + * brief in its companies' own language (E4's headline condition), and returns + * the summary. Offline: recorded pools and cached vectors only. + */ +import type { LearnerSettings } from "../../../src/distribution/learn"; +import type { BriefLanguage } from "../e4-whom-to-check/briefs"; +import { SIMULATION } from "../e4-whom-to-check/config"; +import { createRecorder, loadPool, type LoadedPool } from "../e4-whom-to-check/data"; +import { REPORTED_SEGMENTS, type PoolId } from "../e4-whom-to-check/segments"; +import { summarise, type SegmentOutcomes, type ShortlistSummary } from "./shortlist-report"; +import { ARMS, prepareSegment, replaySeed, type Arm, type SeedOutcome } from "./shortlist-replay"; +import { cachedEmbedder, LOCAL_MODEL, type ReplayEmbedder } from "./vectors"; + +export interface ShortlistRunOptions { + embedder?: ReplayEmbedder; + /** Seeds to replay; E4's twenty by default. */ + seeds?: readonly number[]; + /** Segment ids; all seven reported ones by default. */ + segments?: readonly string[]; + /** `own`: each pool's brief in its companies' language. `en`: every brief in English (E4's first run). */ + briefs?: "own" | "en"; + settings?: Partial; + roundSize?: number; + /** Apply a run's relevance-above-zero rule before ranking (shortlist-replay.ts). */ + zeroScoreRule?: boolean; + onProgress?: (line: string) => void; +} + +export async function runShortlistReplay( + options: ShortlistRunOptions = {} +): Promise<{ summary: ShortlistSummary; segments: SegmentOutcomes[] }> { + const embedder = options.embedder ?? cachedEmbedder({ model: LOCAL_MODEL }); + const seeds = options.seeds ?? SIMULATION.seeds; + const recorder = createRecorder("replay"); + const pools = new Map(); + const segments: SegmentOutcomes[] = []; + for (const segment of REPORTED_SEGMENTS) { + if (options.segments && !options.segments.includes(segment.id)) continue; + let pool = pools.get(segment.pool); + if (!pool) { + pool = await loadPool(recorder, segment.pool); + pools.set(segment.pool, pool); + } + const language: BriefLanguage = options.briefs !== "en" && segment.norwegian ? "no" : "en"; + const prepared = await prepareSegment(embedder, pool, segment, language); + const arms = Object.fromEntries(ARMS.map(arm => [arm, [] as SeedOutcome[]])) as Record< + Arm, + SeedOutcome[] + >; + for (const seed of seeds) { + const outcome = await replaySeed(prepared, seed, { + settings: options.settings, + roundSize: options.roundSize, + zeroScoreRule: options.zeroScoreRule, + }); + for (const arm of ARMS) arms[arm].push(outcome[arm]!); + } + segments.push({ + segment: segment.id, + pool: segment.pool, + briefLanguage: language, + candidates: Math.round(pool.size * SIMULATION.subsample), + good: prepared.labels.reduce((sum, v) => sum + v, 0), + arms, + }); + options.onProgress?.(`${segment.id}: ${seeds.length} seeds replayed`); + } + return { summary: summarise(segments), segments }; +} diff --git a/pipelines/experiments/company-search/production-replay/shortlist.test.ts b/pipelines/experiments/company-search/production-replay/shortlist.test.ts new file mode 100644 index 000000000..b891fc921 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/shortlist.test.ts @@ -0,0 +1,124 @@ +/** + * The shortlist that learns, on the benchmark's pools: E4's seven segments go + * through production's fit-check loop and learner, beside today's fixed + * ranking through the same loop, on the local model and on each of the app's + * built-in embedding models whose vectors are here. + * + * Needs the recorded pools and vectors, which are not in git (they hold public + * contact details); without them the suite is skipped, so it runs on the + * machine that recorded them and not in CI. Three seeds by default (a minute + * or two a model); COMPANY_SEARCH_REPLAY_SEEDS=20 replays all twenty and then + * also checks the numbers against the committed results file. All twenty + * take 8 to 30 minutes a model, the 1,536-dimension one longest and longer + * still on a busy machine, so a model gets an hour before it counts as stuck. + */ +import { describe, expect, it } from "vitest"; + +import { SIMULATION } from "../e4-whom-to-check/config"; +import { offlineEmbedder, REPLAY_MODELS } from "./models"; +import { readShortlistResults } from "./run"; +import { table } from "./shortlist-report"; +import { runShortlistReplay } from "./shortlist-run"; +import { LOCAL_MODEL, recordingsPresent } from "./vectors"; + +const seedCount = Math.min( + SIMULATION.seeds.length, + Math.max(1, Number(process.env.COMPANY_SEARCH_REPLAY_SEEDS ?? 3)) +); +const seeds = SIMULATION.seeds.slice(0, seedCount); +const full = seedCount === SIMULATION.seeds.length; + +describe.skipIf(!recordingsPresent())( + "production replay: the shortlist learns from each verdict", + () => { + for (const model of REPLAY_MODELS) { + it.skipIf(!recordingsPresent(model.id))( + `finds more good companies per check than today's ranking on ${model.id}`, + async () => { + const { summary } = await runShortlistReplay({ + embedder: offlineEmbedder(model.id), + seeds, + }); + console.log(`\n${model.id}\n${table(summary)}\n`); + + for (const segment of summary.perSegment) { + // Where today's ranking already puts a good company at nearly + // every place there is nothing to gain, and looking around + // costs a little: under two companies in a hundred over all + // twenty seeds, a few more over three. + expect( + segment.arms.learner.found100, + `${segment.segment}: found in 100 checks` + ).toBeGreaterThan(segment.arms.today.found100 - (full ? 2 : 6)); + } + const better = summary.perSegment.filter( + s => s.arms.learner.found100 > s.arms.today.found100 + ); + expect(better.length).toBeGreaterThanOrEqual(5); + if (model.id === LOCAL_MODEL) expect(better).toHaveLength(7); + + const gain = summary.vsToday.learner; + expect(gain.found100.mean).toBeGreaterThan(8); + expect(gain.found100.lo).toBeGreaterThan(0); + expect(gain.found200.lo).toBeGreaterThan(0); + // A run fills its 25 places with fewer checks than today's loop. + expect(summary.overall.learner.spent.mean).toBeLessThan( + summary.overall.today.spent.mean - 10 + ); + expect(summary.overall.learner.spent.mean).toBeLessThanOrEqual( + summary.overall["today-in-rounds"].spent.mean + ); + + if (full) { + // The whole replay is deterministic: the committed numbers are these. + expect(summary).toEqual(readShortlistResults()?.byEmbedding[model.id]); + } + }, + 3_600_000 + ); + } + + // A run drops the companies whose relevance is not above zero before + // it ranks; the committed results rank the whole pool, as E4 does. + it.skipIf(!recordingsPresent(LOCAL_MODEL))( + "is not moved for today's ranking by a run's relevance-above-zero rule, and little for the learner", + async () => { + const embedder = offlineEmbedder(LOCAL_MODEL); + const three = SIMULATION.seeds.slice(0, 3); + const whole = await runShortlistReplay({ embedder, seeds: three }); + const ruled = await runShortlistReplay({ + embedder, + seeds: three, + zeroScoreRule: true, + }); + // Nobody at or below zero is among the first hundred of the fixed ranking. + expect(ruled.summary.overall.today.found100).toEqual( + whole.summary.overall.today.found100 + ); + const moved = + ruled.summary.vsToday.learner.found100.mean - + whole.summary.vsToday.learner.found100.mean; + console.log( + `\nlearner minus today in 100 checks, three seeds: ${whole.summary.vsToday.learner.found100.mean} on the whole pool, ${ruled.summary.vsToday.learner.found100.mean} with the rule applied first\n` + ); + expect(Math.abs(moved)).toBeLessThan(3); + expect(ruled.summary.vsToday.learner.found100.lo).toBeGreaterThan(0); + }, + 600_000 + ); + } +); + +describe.skipIf(recordingsPresent())("production replay: the shortlist (recordings absent)", () => { + it("is skipped where the recorded pools are not on the machine", () => { + console.log( + "The company-search recordings are not here (COMPANY_SEARCH_BENCH_CACHE), so the replay did not run. Its last full result is results/production-shortlist.json." + ); + const results = readShortlistResults(); + for (const model of REPLAY_MODELS) { + const gain = results?.byEmbedding[model.id]?.vsToday.learner.found100; + expect(gain, `${model.id} in the results file`).toBeDefined(); + expect(gain!.lo).toBeGreaterThan(0); + } + }); +}); diff --git a/pipelines/experiments/company-search/production-replay/verdict-replay.test.ts b/pipelines/experiments/company-search/production-replay/verdict-replay.test.ts new file mode 100644 index 000000000..ab866e73e --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/verdict-replay.test.ts @@ -0,0 +1,71 @@ +/** + * The learning shortlist on real fit-check verdicts: one pool whose every + * company production's fit check was asked about, replayed through + * production's loop and learner. + * + * Needs the recorded pool, vectors and verdicts, none of which are in git; + * without them the suite is skipped. Three seeds by default; + * COMPANY_SEARCH_REPLAY_SEEDS=20 replays all twenty and then also checks the + * numbers against the committed results file. + */ +import { describe, expect, it } from "vitest"; + +import { SIMULATION } from "../e4-whom-to-check/config"; +import { offlineEmbedder, REPLAY_MODELS } from "./models"; +import { JUDGED_SEGMENT, readVerdictResults } from "./run"; +import { LOCAL_MODEL, recordingsPresent } from "./vectors"; +import { runVerdictReplay, verdictTable } from "./verdict-replay"; +import { readVerdicts } from "./verdicts"; + +const seedCount = Math.min( + SIMULATION.seeds.length, + Math.max(1, Number(process.env.COMPANY_SEARCH_REPLAY_SEEDS ?? 3)) +); +const seeds = SIMULATION.seeds.slice(0, seedCount); +const full = seedCount === SIMULATION.seeds.length; +const recorded = recordingsPresent() && readVerdicts(JUDGED_SEGMENT, "en") !== null; + +describe.skipIf(!recorded)("production replay: the shortlist on real fit-check verdicts", () => { + for (const model of REPLAY_MODELS) { + it.skipIf(!recordingsPresent(model.id))( + `learns from what the fit check really said, on ${model.id}`, + async () => { + const summary = await runVerdictReplay({ + embedder: offlineEmbedder(model.id), + segment: JUDGED_SEGMENT, + seeds, + }); + console.log(`\n${verdictTable(model.id, summary)}\n`); + + // The fit check and the register mostly call the same companies good. + expect(summary.agreement.agree).toBeGreaterThan(0.9); + // Asked again in another batch, a verdict rarely changes. + expect(summary.stability!.changed / summary.stability!.asked).toBeLessThan(0.05); + + for (const counted of [summary.judged, summary.register]) { + const today = counted.overall.today; + const learner = counted.overall.learner; + // Never much behind today's ranking, however good that already is. + expect(learner.found100.mean).toBeGreaterThan(today.found100.mean - 2); + expect(learner.spent.mean).toBeLessThanOrEqual(today.spent.mean); + } + // Where today's ranking is weak (the local model reads Norwegian + // poorly against an English brief), real verdicts rescue it. + if (model.id === LOCAL_MODEL) + expect(summary.judged.vsToday.learner.found100.mean).toBeGreaterThan(30); + + if (full) expect(summary).toEqual(readVerdictResults()?.byEmbedding[model.id]); + }, + 900_000 + ); + } +}); + +describe.skipIf(recorded)("production replay: real verdicts (recordings absent)", () => { + it("is skipped where the recorded verdicts are not on the machine", () => { + console.log( + "The recorded fit-check verdicts are not here (COMPANY_SEARCH_BENCH_CACHE), so the replay did not run. Its last full result is results/production-verdicts.json." + ); + expect(readVerdictResults()?.byEmbedding[LOCAL_MODEL]).toBeDefined(); + }); +}); diff --git a/pipelines/experiments/company-search/production-replay/verdict-replay.ts b/pipelines/experiments/company-search/production-replay/verdict-replay.ts new file mode 100644 index 000000000..3b7a4cb0f --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/verdict-replay.ts @@ -0,0 +1,209 @@ +/** + * The learning shortlist on real fit-check verdicts. + * + * E4 and the shortlist replay answer a check from a register code. Here a + * check answers what production's own fit check said about the company: every + * company of one pool was judged once (record-verdicts.ts) and the verdicts + * are replayed, so the learner meets the yes's and no's a run really gets, + * the model's mistakes included. + * + * Counted two ways: + * judged a company is good when the fit check said yes. What a run is + * after: places on the shortlist it will keep. + * register a company is good by its register code, as in E4, while the + * loop still only sees the fit check's verdicts. Shows whether + * learning from the model's verdicts still finds the companies an + * outside label calls good. + */ +import { SIMULATION } from "../e4-whom-to-check/config"; +import { createRecorder, loadPool } from "../e4-whom-to-check/data"; +import { segmentById } from "../e4-whom-to-check/segments"; +import { round } from "../e4-whom-to-check/stats"; +import { runLaterRunReplay, type LaterRunSummary } from "./later-run"; +import { summarise, type ShortlistSummary } from "./shortlist-report"; +import { + ARMS, + prepareSegment, + replaySeed, + type Arm, + type PreparedSegment, + type SeedOutcome, +} from "./shortlist-replay"; +import type { ReplayEmbedder } from "./vectors"; +import { readVerdicts } from "./verdicts"; + +export interface VerdictSummary { + segment: string; + briefLanguage: string; + judge: string; + companies: number; + /** The fit check's verdicts beside the register's labels, whole pool. */ + agreement: { + judgedYes: number; + registerGood: number; + /** Yes from the fit check and good by the register. */ + both: number; + /** Yes from the fit check, not good by the register. */ + judgeOnly: number; + /** Good by the register, no from the fit check. */ + registerOnly: number; + /** Share of companies on which the two agree. */ + agree: number; + }; + /** Companies asked about twice, in different batches, and how many verdicts changed. */ + stability: { asked: number; changed: number } | null; + /** A company is good when the fit check said yes. */ + judged: ShortlistSummary; + /** A company is good by its register code; the loop sees the fit check's verdicts. */ + register: ShortlistSummary; + /** A second run on companies it has never seen, starting from the first run's kept verdicts (later-run.ts). */ + laterRun: LaterRunSummary; +} + +export class VerdictsMissingError extends Error { + constructor(segment: string) { + super( + `No recorded fit-check verdicts for ${segment} on this machine (record-verdicts.ts records them).` + ); + this.name = "VerdictsMissingError"; + } +} + +async function replay( + prepared: PreparedSegment, + seeds: readonly number[], + good: number, + zeroScoreRule?: boolean +): Promise { + const arms = Object.fromEntries(ARMS.map(arm => [arm, [] as SeedOutcome[]])) as Record< + Arm, + SeedOutcome[] + >; + for (const seed of seeds) { + const outcome = await replaySeed(prepared, seed, { zeroScoreRule }); + for (const arm of ARMS) arms[arm].push(outcome[arm]!); + } + return summarise([ + { + segment: prepared.segment.id, + pool: prepared.segment.pool, + briefLanguage: prepared.language, + candidates: Math.round(prepared.pool.size * SIMULATION.subsample), + good, + arms, + }, + ]); +} + +export async function runVerdictReplay(options: { + embedder: ReplayEmbedder; + segment?: string; + seeds?: readonly number[]; + /** + * Apply a run's relevance-above-zero rule before ranking (shortlist-replay.ts). + * The later-run part always ranks the whole half. + */ + zeroScoreRule?: boolean; +}): Promise { + const segmentId = options.segment ?? "brreg-breweries"; + const seeds = options.seeds ?? SIMULATION.seeds; + const recorded = readVerdicts(segmentId, "en"); + if (!recorded) throw new VerdictsMissingError(segmentId); + const segment = segmentById(segmentId); + const pool = await loadPool(createRecorder("replay"), segment.pool); + if (recorded.poolFingerprint !== pool.fingerprint) + throw new Error("The pool changed since its verdicts were recorded"); + const prepared = await prepareSegment(options.embedder, pool, segment, recorded.briefLanguage); + + const judged = new Uint8Array(pool.size); + for (let i = 0; i < pool.size; i++) { + const verdict = recorded.verdicts[String(i)]; + if (!verdict) throw new Error(`Company ${i} of ${segmentId} has no recorded verdict`); + judged[i] = verdict.fit ? 1 : 0; + } + const register = prepared.labels; + let both = 0; + let judgeOnly = 0; + let registerOnly = 0; + for (let i = 0; i < pool.size; i++) { + if (judged[i] === 1 && register[i] === 1) both += 1; + else if (judged[i] === 1) judgeOnly += 1; + else if (register[i] === 1) registerOnly += 1; + } + const again = Object.entries(recorded.again ?? {}); + const changed = again.filter( + ([i, verdict]) => verdict.fit !== (judged[Number(i)] === 1) + ).length; + + return { + segment: segmentId, + briefLanguage: recorded.briefLanguage, + judge: recorded.judge, + companies: pool.size, + agreement: { + judgedYes: both + judgeOnly, + registerGood: both + registerOnly, + both, + judgeOnly, + registerOnly, + agree: round((pool.size - judgeOnly - registerOnly) / pool.size, 3), + }, + stability: again.length > 0 ? { asked: again.length, changed } : null, + judged: await replay( + { ...prepared, labels: judged, reveals: judged }, + seeds, + both + judgeOnly, + options.zeroScoreRule + ), + register: await replay( + { ...prepared, reveals: judged }, + seeds, + both + registerOnly, + options.zeroScoreRule + ), + laterRun: await runLaterRunReplay({ ...prepared, labels: judged, reveals: judged }, seeds), + }; +} + +const signed = (value: number): string => (value > 0 ? `+${value}` : String(value)); + +/** The table a run prints. */ +export function verdictTable(model: string, summary: VerdictSummary): string { + const a = summary.agreement; + const lines = [ + `${model}, ${summary.segment}: every check answered by the recorded fit check (${summary.judged.seeds} seeds)`, + `fit check said yes to ${a.judgedYes} of ${summary.companies}; the register calls ${a.registerGood} good; both ${a.both}, fit check only ${a.judgeOnly}, register only ${a.registerOnly}; they agree on ${Math.round(a.agree * 1000) / 10}%`, + ]; + if (summary.stability) + lines.push( + `asked twice about ${summary.stability.asked} companies: ${summary.stability.changed} verdicts changed` + ); + for (const [name, s] of [ + ["good = the fit check said yes", summary.judged], + ["good = the register's code", summary.register], + ] as const) { + const o = s.overall; + const d = s.vsToday.learner; + lines.push( + `${name}: found in 25 / 50 / 100 checks: today ${o.today.found25.mean} / ${o.today.found50.mean} / ${o.today.found100.mean}, learner ${o.learner.found25.mean} / ${o.learner.found50.mean} / ${o.learner.found100.mean} (at 100: ${signed(d.found100.mean)}, ${signed(d.found100.lo)} to ${signed(d.found100.hi)} over seeds)` + ); + lines.push( + ` checks a run spends to fill 25 places: today ${o.today.spent.mean}, today in rounds ${o["today-in-rounds"].spent.mean}, learner ${o.learner.spent.mean}` + ); + } + const later = summary.laterRun; + const gap = later.seededMinusFresh; + lines.push( + `a second run on the other half of the pool (${later.half} companies it has never seen), after a first run kept ${later.kept} verdicts:` + ); + for (const arm of ["today", "fresh", "seeded"] as const) { + const a = later.arms[arm]; + lines.push( + ` ${arm.padEnd(7)} yes in its first 10 / 25 / 50 checks: ${a.found10} / ${a.found25} / ${a.found50}; checks to fill 25 places: ${a.spent}` + ); + } + lines.push( + ` seeded minus fresh: first 10 checks ${signed(gap.found10.mean)} (${signed(gap.found10.lo)} to ${signed(gap.found10.hi)}), first 25 ${signed(gap.found25.mean)} (${signed(gap.found25.lo)} to ${signed(gap.found25.hi)}), checks to fill 25 ${signed(gap.spent.mean)} (${signed(gap.spent.lo)} to ${signed(gap.spent.hi)})` + ); + return lines.join("\n"); +} diff --git a/pipelines/experiments/company-search/production-replay/verdicts.ts b/pipelines/experiments/company-search/production-replay/verdicts.ts new file mode 100644 index 000000000..ed5b4bd71 --- /dev/null +++ b/pipelines/experiments/company-search/production-replay/verdicts.ts @@ -0,0 +1,68 @@ +/** + * Real fit-check verdicts on a benchmark pool, kept on disk beside the + * recordings: what production's own fit check (src/distribution/judge.ts) said + * about every company of a pool, asked once. + * + * E4's verdicts come from register codes and directory tags. These are a + * chat model's, with its prompt and its mistakes, so a replay over them shows + * how the learning shortlist behaves on the verdicts a run really gets. + * + * The file holds a verdict and the model's one-sentence reason per company; + * like the recordings it is never committed. + */ +import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs"; +import path from "node:path"; + +import type { FitVerdict } from "../../../src/distribution/semantic"; +import type { BriefLanguage } from "../e4-whom-to-check/briefs"; +import { DEFAULT_CACHE_DIR } from "../lib/recorder"; + +/** The judge the verdicts were recorded with: the dev configuration's fast route. */ +export const JUDGE_ID = "gemini-3.8-flash-fast"; + +/** Where each Norwegian pool's seller wants its buyers, as a run tells the fit check. */ +export const WHERE: Record = { + "brreg-coffee-tea": "Norway", + "brreg-breweries": "Norway", + "brreg-dental-bergen": "Bergen, Norway", +}; + +export interface RecordedVerdicts { + segment: string; + briefLanguage: BriefLanguage; + judge: string; + /** The pool's fingerprint when it was judged: a re-recorded pool needs new verdicts. */ + poolFingerprint: string; + /** Pool index → verdict. */ + verdicts: Record; + /** A second opinion on some companies, asked in other batches: how stable a verdict is. */ + again?: Record; +} + +export function verdictsFile( + segment: string, + language: BriefLanguage, + judge = JUDGE_ID, + dir = DEFAULT_CACHE_DIR +): string { + return path.join(dir, "verdicts", judge, `${segment}.${language}.json`); +} + +export function readVerdicts( + segment: string, + language: BriefLanguage, + judge = JUDGE_ID +): RecordedVerdicts | null { + const file = verdictsFile(segment, language, judge); + if (!existsSync(file)) return null; + return JSON.parse(readFileSync(file, "utf8")) as RecordedVerdicts; +} + +export function writeVerdicts(recorded: RecordedVerdicts): void { + const file = verdictsFile(recorded.segment, recorded.briefLanguage, recorded.judge); + mkdirSync(path.dirname(file), { recursive: true }); + // Written beside and moved into place, so a stopped run never leaves half a file. + const beside = `${file}.part`; + writeFileSync(beside, JSON.stringify(recorded)); + renameSync(beside, file); +} diff --git a/pipelines/experiments/company-search/results/production-shortlist.json b/pipelines/experiments/company-search/results/production-shortlist.json new file mode 100644 index 000000000..156e986ff --- /dev/null +++ b/pipelines/experiments/company-search/results/production-shortlist.json @@ -0,0 +1,1376 @@ +{ + "experiment": "production-replay: the shortlist learns from each verdict", + "question": "Does production's own ranking code find more good companies per fit check than today's fixed ranking, on E4's pools?", + "design": { + "code": "src/distribution/shortlist.ts (fillShortlist) and src/distribution/learn.ts (createShortlistLearner), as production runs them", + "pools": "E4's seven reported segments, each with a brief in its companies' own language (E4's headline condition)", + "check": "one check reveals one company's hidden label (directory tag or register code) and costs 1", + "candidates": "a seed's 80% draw of the pool, in today's order: relevance, ties in the draw's order", + "arms": { + "today": "the fixed ranking through production's loop: 2 companies per open shortlist place each round", + "today-in-rounds": "the fixed ranking asked 10 at a time, so the effect of the round size alone is visible", + "learner": "production's learner picks every round of 10" + }, + "metrics": { + "found": "good companies among the first 25, 50, 100, 200 checks, with no shortlist to fill", + "checksTo25": "checks until the 25th good company was checked, capped at 500", + "spent": "checks production's loop makes before a 25-place shortlist is full, in whole rounds", + "rounds": "rounds of that run. The fit check makes one model call per twenty companies of a round: three for today's first round of fifty, one for a round of ten" + }, + "learner": { + "dims": 48, + "noiseSd": 0.5, + "priorSdScore": 0.25, + "priorSdBias": 1, + "priorSdProjection": 0.4, + "bonus": 0.5, + "rounds": 6 + }, + "embeddingModels": { + "nomic-embed-text": "nomic-embed-text (local, the benchmark's model)", + "gemini-embedding-001@768": "gemini-embedding-001 at 768 dimensions (index gemini-embedding-768, the one the registry recommends)", + "text-embedding-3-large@1536": "text-embedding-3-large at 1536 dimensions (index legacy-openai-1536, the default)" + }, + "intervals": "95% percentile bootstrap, 2,000 resamples: over pools and then seeds, as in E4" + }, + "byEmbedding": { + "nomic-embed-text": { + "seeds": 20, + "perSegment": [ + { + "segment": "yc-devtools", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 615, + "arms": { + "today": { + "found25": 11.3, + "found50": 24.1, + "found100": 46.7, + "found200": 88.25, + "checksTo25": 52.2, + "spent": 53.1, + "rounds": 2 + }, + "today-in-rounds": { + "found25": 11.3, + "found50": 24.1, + "found100": 46.7, + "found200": 88.25, + "checksTo25": 52.2, + "spent": 52.8, + "rounds": 6.05 + }, + "learner": { + "found25": 12.9, + "found50": 29.05, + "found100": 61.8, + "found200": 119.45, + "checksTo25": 43.65, + "spent": 45.1, + "rounds": 4.9 + } + } + }, + { + "segment": "yc-healthcare", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 702, + "arms": { + "today": { + "found25": 22.55, + "found50": 45.3, + "found100": 87.05, + "found200": 163.95, + "checksTo25": 27.65, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 22.55, + "found50": 45.3, + "found100": 87.05, + "found200": 163.95, + "checksTo25": 27.65, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 21.95, + "found50": 44.85, + "found100": 91.55, + "found200": 183.7, + "checksTo25": 28.3, + "spent": 30.2, + "rounds": 3.1 + } + } + }, + { + "segment": "yc-climate-energy", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 238, + "arms": { + "today": { + "found25": 23.1, + "found50": 39, + "found100": 67.65, + "found200": 91.95, + "checksTo25": 27.15, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 23.1, + "found50": 39, + "found100": 67.65, + "found200": 91.95, + "checksTo25": 27.15, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 21, + "found50": 39.2, + "found100": 74.5, + "found200": 125.95, + "checksTo25": 30.1, + "spent": 31.1, + "rounds": 3.35 + } + } + }, + { + "segment": "yc-logistics", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 245, + "arms": { + "today": { + "found25": 14.8, + "found50": 24.5, + "found100": 37.4, + "found200": 55.1, + "checksTo25": 50.75, + "spent": 51.9, + "rounds": 1.6 + }, + "today-in-rounds": { + "found25": 14.8, + "found50": 24.5, + "found100": 37.4, + "found200": 55.1, + "checksTo25": 50.75, + "spent": 51.4, + "rounds": 5.7 + }, + "learner": { + "found25": 19.3, + "found50": 39.35, + "found100": 72.3, + "found200": 113.15, + "checksTo25": 31.35, + "spent": 32.7, + "rounds": 3.7 + } + } + }, + { + "segment": "brreg-coffee-tea", + "pool": "brreg-food", + "briefLanguage": "no", + "candidates": 3484, + "good": 109, + "arms": { + "today": { + "found25": 13.15, + "found50": 20.2, + "found100": 28.65, + "found200": 41.95, + "checksTo25": 67.9, + "spent": 68.5, + "rounds": 4.45 + }, + "today-in-rounds": { + "found25": 13.15, + "found50": 20.2, + "found100": 28.65, + "found200": 41.95, + "checksTo25": 67.9, + "spent": 68.5, + "rounds": 8.55 + }, + "learner": { + "found25": 19.5, + "found50": 44.5, + "found100": 76.1, + "found200": 77.55, + "checksTo25": 30.5, + "spent": 31.1, + "rounds": 3.55 + } + } + }, + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "no", + "candidates": 1138, + "good": 233, + "arms": { + "today": { + "found25": 23.95, + "found50": 42.5, + "found100": 71.6, + "found200": 101.45, + "checksTo25": 26.15, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 23.95, + "found50": 42.5, + "found100": 71.6, + "found200": 101.45, + "checksTo25": 26.15, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 23.75, + "found50": 47.4, + "found100": 91.5, + "found200": 154.6, + "checksTo25": 26.25, + "spent": 30, + "rounds": 3 + } + } + }, + { + "segment": "brreg-dental-bergen", + "pool": "brreg-health-bergen", + "briefLanguage": "no", + "candidates": 2954, + "good": 421, + "arms": { + "today": { + "found25": 22.85, + "found50": 40.3, + "found100": 75.2, + "found200": 132, + "checksTo25": 28.8, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 22.85, + "found50": 40.3, + "found100": 75.2, + "found200": 132, + "checksTo25": 28.8, + "spent": 30.7, + "rounds": 3.3 + }, + "learner": { + "found25": 22.9, + "found50": 47.45, + "found100": 96.85, + "found200": 195, + "checksTo25": 27.4, + "spent": 30, + "rounds": 3 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 18.81, + "lo": 15.09, + "hi": 22.13 + }, + "found50": { + "mean": 33.7, + "lo": 26.59, + "hi": 40.26 + }, + "found100": { + "mean": 59.18, + "lo": 44.61, + "hi": 73.56 + }, + "found200": { + "mean": 96.38, + "lo": 68.34, + "hi": 126.16 + }, + "checksTo25": { + "mean": 40.09, + "lo": 30.48, + "hi": 51.7 + }, + "spent": { + "mean": 53.36, + "lo": 50.16, + "hi": 58.71 + }, + "rounds": { + "mean": 1.7, + "lo": 1.1, + "hi": 2.7 + } + }, + "today-in-rounds": { + "found25": { + "mean": 18.81, + "lo": 15.09, + "hi": 22.13 + }, + "found50": { + "mean": 33.7, + "lo": 26.59, + "hi": 40.26 + }, + "found100": { + "mean": 59.18, + "lo": 44.61, + "hi": 73.56 + }, + "found200": { + "mean": 96.38, + "lo": 68.34, + "hi": 126.16 + }, + "checksTo25": { + "mean": 40.09, + "lo": 30.48, + "hi": 51.7 + }, + "spent": { + "mean": 41.91, + "lo": 33.06, + "hi": 53.01 + }, + "rounds": { + "mean": 4.7, + "lo": 3.4, + "hi": 6.2 + } + }, + "learner": { + "found25": { + "mean": 20.19, + "lo": 17.55, + "hi": 22.34 + }, + "found50": { + "mean": 41.69, + "lo": 36.97, + "hi": 45.58 + }, + "found100": { + "mean": 80.66, + "lo": 71.81, + "hi": 89.56 + }, + "found200": { + "mean": 138.49, + "lo": 110.45, + "hi": 167.53 + }, + "checksTo25": { + "mean": 31.08, + "lo": 27.93, + "hi": 35.59 + }, + "spent": { + "mean": 32.89, + "lo": 30.34, + "hi": 37.16 + }, + "rounds": { + "mean": 3.5, + "lo": 3.1, + "hi": 4 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -11.44, + "lo": -17.19, + "hi": -5.43 + }, + "rounds": { + "mean": 2.9, + "lo": 2.3, + "hi": 3.6 + } + }, + "learner": { + "found25": { + "mean": 1.37, + "lo": -0.54, + "hi": 3.45 + }, + "found50": { + "mean": 7.99, + "lo": 2.65, + "hi": 14.29 + }, + "found100": { + "mean": 21.48, + "lo": 11.91, + "hi": 32.11 + }, + "found200": { + "mean": 42.11, + "lo": 31.01, + "hi": 52.85 + }, + "checksTo25": { + "mean": -9.01, + "lo": -19.7, + "hi": -0.28 + }, + "spent": { + "mean": -20.47, + "lo": -27.01, + "hi": -14.76 + }, + "rounds": { + "mean": 1.8, + "lo": 0.8, + "hi": 2.4 + } + } + } + }, + "gemini-embedding-001@768": { + "seeds": 20, + "perSegment": [ + { + "segment": "yc-devtools", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 615, + "arms": { + "today": { + "found25": 15.05, + "found50": 31.65, + "found100": 56.95, + "found200": 101.95, + "checksTo25": 39.15, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 15.05, + "found50": 31.65, + "found100": 56.95, + "found200": 101.95, + "checksTo25": 39.15, + "spent": 40.6, + "rounds": 4.2 + }, + "learner": { + "found25": 12.55, + "found50": 27.55, + "found100": 63.35, + "found200": 131.85, + "checksTo25": 46.55, + "spent": 48, + "rounds": 5.3 + } + } + }, + { + "segment": "yc-healthcare", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 702, + "arms": { + "today": { + "found25": 15.95, + "found50": 27.55, + "found100": 58.15, + "found200": 106.15, + "checksTo25": 44.1, + "spent": 50.1, + "rounds": 1.05 + }, + "today-in-rounds": { + "found25": 15.95, + "found50": 27.55, + "found100": 58.15, + "found200": 106.15, + "checksTo25": 44.1, + "spent": 44.9, + "rounds": 5.2 + }, + "learner": { + "found25": 20.45, + "found50": 44.3, + "found100": 91.9, + "found200": 185.4, + "checksTo25": 29.65, + "spent": 30.7, + "rounds": 3.15 + } + } + }, + { + "segment": "yc-climate-energy", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 238, + "arms": { + "today": { + "found25": 20.55, + "found50": 35.3, + "found100": 53.3, + "found200": 74.55, + "checksTo25": 31.35, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 20.55, + "found50": 35.3, + "found100": 53.3, + "found200": 74.55, + "checksTo25": 31.35, + "spent": 32.4, + "rounds": 3.6 + }, + "learner": { + "found25": 21.4, + "found50": 41.65, + "found100": 80.25, + "found200": 134.8, + "checksTo25": 29.5, + "spent": 30.5, + "rounds": 3.2 + } + } + }, + { + "segment": "yc-logistics", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 245, + "arms": { + "today": { + "found25": 18.45, + "found50": 34.1, + "found100": 54.05, + "found200": 74.7, + "checksTo25": 34.6, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 18.45, + "found50": 34.1, + "found100": 54.05, + "found200": 74.7, + "checksTo25": 34.6, + "spent": 36.3, + "rounds": 4.1 + }, + "learner": { + "found25": 21.2, + "found50": 40.7, + "found100": 81.6, + "found200": 124.75, + "checksTo25": 30.1, + "spent": 31.5, + "rounds": 3.3 + } + } + }, + { + "segment": "brreg-coffee-tea", + "pool": "brreg-food", + "briefLanguage": "no", + "candidates": 3484, + "good": 109, + "arms": { + "today": { + "found25": 25, + "found50": 49.2, + "found100": 70.5, + "found200": 76.6, + "checksTo25": 25, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 25, + "found50": 49.2, + "found100": 70.5, + "found200": 76.6, + "checksTo25": 25, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 24.5, + "found50": 48.85, + "found100": 81.2, + "found200": 81.6, + "checksTo25": 25.5, + "spent": 30, + "rounds": 3 + } + } + }, + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "no", + "candidates": 1138, + "good": 233, + "arms": { + "today": { + "found25": 24.25, + "found50": 48.4, + "found100": 96.5, + "found200": 156.15, + "checksTo25": 25.75, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 24.25, + "found50": 48.4, + "found100": 96.5, + "found200": 156.15, + "checksTo25": 25.75, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 23.4, + "found50": 47.6, + "found100": 95.6, + "found200": 169.45, + "checksTo25": 26.65, + "spent": 30, + "rounds": 3 + } + } + }, + { + "segment": "brreg-dental-bergen", + "pool": "brreg-health-bergen", + "briefLanguage": "no", + "candidates": 2954, + "good": 421, + "arms": { + "today": { + "found25": 25, + "found50": 49.25, + "found100": 98.35, + "found200": 193.7, + "checksTo25": 25, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 25, + "found50": 49.25, + "found100": 98.35, + "found200": 193.7, + "checksTo25": 25, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 24.95, + "found50": 48.9, + "found100": 97.9, + "found200": 197.7, + "checksTo25": 25.05, + "spent": 30, + "rounds": 3 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 20.61, + "lo": 17.73, + "hi": 23.44 + }, + "found50": { + "mean": 39.35, + "lo": 33.08, + "hi": 45.89 + }, + "found100": { + "mean": 69.69, + "lo": 57.02, + "hi": 84.24 + }, + "found200": { + "mean": 111.97, + "lo": 83.41, + "hi": 145.74 + }, + "checksTo25": { + "mean": 32.14, + "lo": 27.23, + "hi": 37.41 + }, + "spent": { + "mean": 50.01, + "lo": 50, + "hi": 50.06 + }, + "rounds": { + "mean": 1, + "lo": 1, + "hi": 1 + } + }, + "today-in-rounds": { + "found25": { + "mean": 20.61, + "lo": 17.73, + "hi": 23.44 + }, + "found50": { + "mean": 39.35, + "lo": 33.08, + "hi": 45.89 + }, + "found100": { + "mean": 69.69, + "lo": 57.02, + "hi": 84.24 + }, + "found200": { + "mean": 111.97, + "lo": 83.41, + "hi": 145.74 + }, + "checksTo25": { + "mean": 32.14, + "lo": 27.23, + "hi": 37.41 + }, + "spent": { + "mean": 34.89, + "lo": 31.16, + "hi": 39.14 + }, + "rounds": { + "mean": 3.7, + "lo": 3.2, + "hi": 4.3 + } + }, + "learner": { + "found25": { + "mean": 21.21, + "lo": 18.09, + "hi": 23.61 + }, + "found50": { + "mean": 42.79, + "lo": 37.29, + "hi": 47.24 + }, + "found100": { + "mean": 84.54, + "lo": 75.79, + "hi": 92.34 + }, + "found200": { + "mean": 146.51, + "lo": 118.77, + "hi": 173.76 + }, + "checksTo25": { + "mean": 30.43, + "lo": 26.58, + "hi": 36.14 + }, + "spent": { + "mean": 32.96, + "lo": 30.13, + "hi": 38.14 + }, + "rounds": { + "mean": 3.4, + "lo": 3, + "hi": 4.1 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -15.13, + "lo": -18.84, + "hi": -10.89 + }, + "rounds": { + "mean": 2.7, + "lo": 2.2, + "hi": 3.3 + } + }, + "learner": { + "found25": { + "mean": 0.6, + "lo": -0.96, + "hi": 2.32 + }, + "found50": { + "mean": 3.44, + "lo": -1, + "hi": 8.91 + }, + "found100": { + "mean": 14.86, + "lo": 5.11, + "hi": 25.19 + }, + "found200": { + "mean": 34.54, + "lo": 15.04, + "hi": 56.07 + }, + "checksTo25": { + "mean": -1.71, + "lo": -6.91, + "hi": 2.59 + }, + "spent": { + "mean": -17.06, + "lo": -19.89, + "hi": -11.87 + }, + "rounds": { + "mean": 2.4, + "lo": 2, + "hi": 3.1 + } + } + } + }, + "text-embedding-3-large@1536": { + "seeds": 20, + "perSegment": [ + { + "segment": "yc-devtools", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 615, + "arms": { + "today": { + "found25": 8.9, + "found50": 20.3, + "found100": 35.7, + "found200": 65.9, + "checksTo25": 66.6, + "spent": 67.2, + "rounds": 4.45 + }, + "today-in-rounds": { + "found25": 8.9, + "found50": 20.3, + "found100": 35.7, + "found200": 65.9, + "checksTo25": 66.6, + "spent": 67.2, + "rounds": 8.65 + }, + "learner": { + "found25": 14.3, + "found50": 30.65, + "found100": 63.05, + "found200": 121.15, + "checksTo25": 40.35, + "spent": 41.5, + "rounds": 4.5 + } + } + }, + { + "segment": "yc-healthcare", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 702, + "arms": { + "today": { + "found25": 22.45, + "found50": 45.85, + "found100": 92.6, + "found200": 179.25, + "checksTo25": 27.65, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 22.45, + "found50": 45.85, + "found100": 92.6, + "found200": 179.25, + "checksTo25": 27.65, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 22, + "found50": 45.1, + "found100": 92.45, + "found200": 187.1, + "checksTo25": 28.1, + "spent": 30, + "rounds": 3 + } + } + }, + { + "segment": "yc-climate-energy", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 238, + "arms": { + "today": { + "found25": 23.4, + "found50": 45, + "found100": 80.2, + "found200": 110, + "checksTo25": 26.6, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 23.4, + "found50": 45, + "found100": 80.2, + "found200": 110, + "checksTo25": 26.6, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 20.8, + "found50": 40.8, + "found100": 78.5, + "found200": 131.75, + "checksTo25": 30.3, + "spent": 32, + "rounds": 3.6 + } + } + }, + { + "segment": "yc-logistics", + "pool": "yc", + "briefLanguage": "en", + "candidates": 4997, + "good": 245, + "arms": { + "today": { + "found25": 16.65, + "found50": 30.45, + "found100": 50.85, + "found200": 72.9, + "checksTo25": 40.4, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 16.65, + "found50": 30.45, + "found100": 50.85, + "found200": 72.9, + "checksTo25": 40.4, + "spent": 41.8, + "rounds": 4.65 + }, + "learner": { + "found25": 20.6, + "found50": 41.6, + "found100": 75.8, + "found200": 119.1, + "checksTo25": 29.85, + "spent": 31, + "rounds": 3.25 + } + } + }, + { + "segment": "brreg-coffee-tea", + "pool": "brreg-food", + "briefLanguage": "no", + "candidates": 3484, + "good": 109, + "arms": { + "today": { + "found25": 24.65, + "found50": 41.2, + "found100": 56.95, + "found200": 61.7, + "checksTo25": 25.55, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 24.65, + "found50": 41.2, + "found100": 56.95, + "found200": 61.7, + "checksTo25": 25.55, + "spent": 30.1, + "rounds": 3.05 + }, + "learner": { + "found25": 23, + "found50": 48, + "found100": 80.65, + "found200": 81.75, + "checksTo25": 27, + "spent": 30, + "rounds": 3 + } + } + }, + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "no", + "candidates": 1138, + "good": 233, + "arms": { + "today": { + "found25": 21.85, + "found50": 44.05, + "found100": 84.75, + "found200": 139.3, + "checksTo25": 29.55, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 21.85, + "found50": 44.05, + "found100": 84.75, + "found200": 139.3, + "checksTo25": 29.55, + "spent": 30.5, + "rounds": 3.25 + }, + "learner": { + "found25": 21.6, + "found50": 45.7, + "found100": 93.4, + "found200": 168.15, + "checksTo25": 28.75, + "spent": 30, + "rounds": 3 + } + } + }, + { + "segment": "brreg-dental-bergen", + "pool": "brreg-health-bergen", + "briefLanguage": "no", + "candidates": 2954, + "good": 421, + "arms": { + "today": { + "found25": 17, + "found50": 35.35, + "found100": 68.1, + "found200": 130.55, + "checksTo25": 35.95, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 17, + "found50": 35.35, + "found100": 68.1, + "found200": 130.55, + "checksTo25": 35.95, + "spent": 38, + "rounds": 4 + }, + "learner": { + "found25": 19.4, + "found50": 44.2, + "found100": 93.7, + "found200": 192.7, + "checksTo25": 30.65, + "spent": 31.8, + "rounds": 3.65 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 19.27, + "lo": 15.14, + "hi": 22.73 + }, + "found50": { + "mean": 37.46, + "lo": 30.25, + "hi": 43.41 + }, + "found100": { + "mean": 67.02, + "lo": 52.83, + "hi": 80.24 + }, + "found200": { + "mean": 108.51, + "lo": 80.45, + "hi": 139.33 + }, + "checksTo25": { + "mean": 36.04, + "lo": 28.01, + "hi": 47.54 + }, + "spent": { + "mean": 52.46, + "lo": 50, + "hi": 57.63 + }, + "rounds": { + "mean": 1.5, + "lo": 1, + "hi": 2.6 + } + }, + "today-in-rounds": { + "found25": { + "mean": 19.27, + "lo": 15.14, + "hi": 22.73 + }, + "found50": { + "mean": 37.46, + "lo": 30.25, + "hi": 43.41 + }, + "found100": { + "mean": 67.02, + "lo": 52.83, + "hi": 80.24 + }, + "found200": { + "mean": 108.51, + "lo": 80.45, + "hi": 139.33 + }, + "checksTo25": { + "mean": 36.04, + "lo": 28.01, + "hi": 47.54 + }, + "spent": { + "mean": 38.23, + "lo": 30.4, + "hi": 49.06 + }, + "rounds": { + "mean": 4.2, + "lo": 3.1, + "hi": 5.9 + } + }, + "learner": { + "found25": { + "mean": 20.24, + "lo": 18, + "hi": 21.9 + }, + "found50": { + "mean": 42.29, + "lo": 37.94, + "hi": 45.56 + }, + "found100": { + "mean": 82.51, + "lo": 74.18, + "hi": 90.17 + }, + "found200": { + "mean": 143.1, + "lo": 115.28, + "hi": 170.93 + }, + "checksTo25": { + "mean": 30.71, + "lo": 28.36, + "hi": 34.29 + }, + "spent": { + "mean": 32.33, + "lo": 30.29, + "hi": 35.63 + }, + "rounds": { + "mean": 3.4, + "lo": 3.1, + "hi": 3.9 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -14.23, + "lo": -19.6, + "hi": -8.36 + }, + "rounds": { + "mean": 2.7, + "lo": 2.1, + "hi": 3.4 + } + }, + "learner": { + "found25": { + "mean": 0.97, + "lo": -1.01, + "hi": 3.16 + }, + "found50": { + "mean": 4.84, + "lo": 0.56, + "hi": 8.68 + }, + "found100": { + "mean": 15.49, + "lo": 6.45, + "hi": 23.42 + }, + "found200": { + "mean": 34.59, + "lo": 21.09, + "hi": 48.35 + }, + "checksTo25": { + "mean": -5.33, + "lo": -13.42, + "hi": 0.76 + }, + "spent": { + "mean": -20.13, + "lo": -22.24, + "hi": -18.7 + }, + "rounds": { + "mean": 1.9, + "lo": 1.3, + "hi": 2.4 + } + } + } + } + } +} diff --git a/pipelines/experiments/company-search/results/production-verdicts.json b/pipelines/experiments/company-search/results/production-verdicts.json new file mode 100644 index 000000000..b7a911313 --- /dev/null +++ b/pipelines/experiments/company-search/results/production-verdicts.json @@ -0,0 +1,1600 @@ +{ + "experiment": "production-replay: the learning shortlist on real fit-check verdicts", + "question": "When a check answers what production's fit check really said, does the learning shortlist still find more companies per check than today's ranking?", + "design": { + "code": "src/distribution/shortlist.ts (fillShortlist) and src/distribution/learn.ts (createShortlistLearner), as production runs them", + "pool": "brreg-breweries: every company judged once by production's fit check (src/distribution/judge.ts, unchanged), English brief, \"Norway\" as the place", + "judge": "gemini-3.8-flash-fast: the fast route of apps/web/config/chat-models.yaml through OpenRouter. A deployment whose chat routes point at another model may judge differently; none was called", + "check": "one check answers the recorded verdict on that company and costs 1; the loop and the learner see nothing else", + "counted": { + "judged": "a company is good when the fit check said yes", + "register": "a company is good by its register code, as in E4" + }, + "stability": "200 companies were asked about a second time in other batches; `changed` is how many verdicts differ", + "candidates": "a seed's 80% draw of the pool, in today's order", + "laterRun": "the pool is split in two at random. A first run fills its shortlist on one half with the learner and keeps its verdicts; a second run meets the other half three ways: today's ranking, the learner starting from nothing (`fresh`), and the learner starting from the kept verdicts (`seeded`)", + "embeddingModels": { + "nomic-embed-text": "nomic-embed-text (local, the benchmark's model)", + "gemini-embedding-001@768": "gemini-embedding-001 at 768 dimensions (index gemini-embedding-768, the one the registry recommends)", + "text-embedding-3-large@1536": "text-embedding-3-large at 1536 dimensions (index legacy-openai-1536, the default)" + }, + "intervals": "95% percentile bootstrap over the seeds of this one pool: they say how stable the figure is on this pool, not how far it carries to another" + }, + "byEmbedding": { + "nomic-embed-text": { + "segment": "brreg-breweries", + "briefLanguage": "en", + "judge": "gemini-3.8-flash-fast", + "companies": 1422, + "agreement": { + "judgedYes": 225, + "registerGood": 233, + "both": 206, + "judgeOnly": 19, + "registerOnly": 27, + "agree": 0.968 + }, + "stability": { + "asked": 200, + "changed": 3 + }, + "judged": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "en", + "candidates": 1138, + "good": 225, + "arms": { + "today": { + "found25": 9.55, + "found50": 22.15, + "found100": 36.7, + "found200": 62.9, + "checksTo25": 55.85, + "spent": 57, + "rounds": 2.45 + }, + "today-in-rounds": { + "found25": 9.55, + "found50": 22.15, + "found100": 36.7, + "found200": 62.9, + "checksTo25": 55.85, + "spent": 57, + "rounds": 6.5 + }, + "learner": { + "found25": 15.65, + "found50": 38.25, + "found100": 84.65, + "found200": 157.2, + "checksTo25": 35.4, + "spent": 38.6, + "rounds": 4 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 9.55, + "lo": 9, + "hi": 10.2 + }, + "found50": { + "mean": 22.15, + "lo": 21.4, + "hi": 22.95 + }, + "found100": { + "mean": 36.7, + "lo": 35.8, + "hi": 37.7 + }, + "found200": { + "mean": 62.9, + "lo": 61.95, + "hi": 63.95 + }, + "checksTo25": { + "mean": 55.85, + "lo": 54.05, + "hi": 57.6 + }, + "spent": { + "mean": 57, + "lo": 55.3, + "hi": 58.6 + }, + "rounds": { + "mean": 2.5, + "lo": 2.1, + "hi": 2.8 + } + }, + "today-in-rounds": { + "found25": { + "mean": 9.55, + "lo": 9, + "hi": 10.2 + }, + "found50": { + "mean": 22.15, + "lo": 21.4, + "hi": 22.95 + }, + "found100": { + "mean": 36.7, + "lo": 35.8, + "hi": 37.7 + }, + "found200": { + "mean": 62.9, + "lo": 61.95, + "hi": 63.95 + }, + "checksTo25": { + "mean": 55.85, + "lo": 54.05, + "hi": 57.6 + }, + "spent": { + "mean": 57, + "lo": 55.3, + "hi": 58.6 + }, + "rounds": { + "mean": 6.5, + "lo": 6.2, + "hi": 6.9 + } + }, + "learner": { + "found25": { + "mean": 15.65, + "lo": 14.85, + "hi": 16.5 + }, + "found50": { + "mean": 38.25, + "lo": 37.45, + "hi": 39.1 + }, + "found100": { + "mean": 84.65, + "lo": 83.8, + "hi": 85.55 + }, + "found200": { + "mean": 157.2, + "lo": 155.05, + "hi": 159.1 + }, + "checksTo25": { + "mean": 35.4, + "lo": 34.5, + "hi": 36.2 + }, + "spent": { + "mean": 38.6, + "lo": 37.4, + "hi": 39.6 + }, + "rounds": { + "mean": 4, + "lo": 4, + "hi": 4 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "rounds": { + "mean": 4.1, + "lo": 4, + "hi": 4.2 + } + }, + "learner": { + "found25": { + "mean": 6.1, + "lo": 5.25, + "hi": 7.05 + }, + "found50": { + "mean": 16.1, + "lo": 14.9, + "hi": 17.4 + }, + "found100": { + "mean": 47.95, + "lo": 46.7, + "hi": 49.2 + }, + "found200": { + "mean": 94.3, + "lo": 92.25, + "hi": 96.15 + }, + "checksTo25": { + "mean": -20.45, + "lo": -22.35, + "hi": -18.65 + }, + "spent": { + "mean": -18.4, + "lo": -20.5, + "hi": -16.4 + }, + "rounds": { + "mean": 1.6, + "lo": 1.3, + "hi": 1.9 + } + } + } + }, + "register": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "en", + "candidates": 1138, + "good": 233, + "arms": { + "today": { + "found25": 8.65, + "found50": 19.75, + "found100": 30.7, + "found200": 58, + "checksTo25": 68.1, + "spent": 57, + "rounds": 2.45 + }, + "today-in-rounds": { + "found25": 8.65, + "found50": 19.75, + "found100": 30.7, + "found200": 58, + "checksTo25": 68.1, + "spent": 57, + "rounds": 6.5 + }, + "learner": { + "found25": 14.75, + "found50": 37.65, + "found100": 84.65, + "found200": 153.6, + "checksTo25": 36.6, + "spent": 38.6, + "rounds": 4 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 8.65, + "lo": 8, + "hi": 9.3 + }, + "found50": { + "mean": 19.75, + "lo": 19.05, + "hi": 20.45 + }, + "found100": { + "mean": 30.7, + "lo": 29.75, + "hi": 31.7 + }, + "found200": { + "mean": 58, + "lo": 56.95, + "hi": 59.15 + }, + "checksTo25": { + "mean": 68.1, + "lo": 64.6, + "hi": 71.8 + }, + "spent": { + "mean": 57, + "lo": 55.3, + "hi": 58.6 + }, + "rounds": { + "mean": 2.5, + "lo": 2.1, + "hi": 2.8 + } + }, + "today-in-rounds": { + "found25": { + "mean": 8.65, + "lo": 8, + "hi": 9.3 + }, + "found50": { + "mean": 19.75, + "lo": 19.05, + "hi": 20.45 + }, + "found100": { + "mean": 30.7, + "lo": 29.75, + "hi": 31.7 + }, + "found200": { + "mean": 58, + "lo": 56.95, + "hi": 59.15 + }, + "checksTo25": { + "mean": 68.1, + "lo": 64.6, + "hi": 71.8 + }, + "spent": { + "mean": 57, + "lo": 55.3, + "hi": 58.6 + }, + "rounds": { + "mean": 6.5, + "lo": 6.2, + "hi": 6.9 + } + }, + "learner": { + "found25": { + "mean": 14.75, + "lo": 14.05, + "hi": 15.6 + }, + "found50": { + "mean": 37.65, + "lo": 36.7, + "hi": 38.55 + }, + "found100": { + "mean": 84.65, + "lo": 83.65, + "hi": 85.65 + }, + "found200": { + "mean": 153.6, + "lo": 151.7, + "hi": 155.35 + }, + "checksTo25": { + "mean": 36.6, + "lo": 35.75, + "hi": 37.4 + }, + "spent": { + "mean": 38.6, + "lo": 37.4, + "hi": 39.6 + }, + "rounds": { + "mean": 4, + "lo": 4, + "hi": 4 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "rounds": { + "mean": 4.1, + "lo": 4, + "hi": 4.2 + } + }, + "learner": { + "found25": { + "mean": 6.1, + "lo": 5.3, + "hi": 7.1 + }, + "found50": { + "mean": 17.9, + "lo": 16.6, + "hi": 19.25 + }, + "found100": { + "mean": 53.95, + "lo": 52.4, + "hi": 55.4 + }, + "found200": { + "mean": 95.6, + "lo": 93.65, + "hi": 97.5 + }, + "checksTo25": { + "mean": -31.5, + "lo": -35.55, + "hi": -27.7 + }, + "spent": { + "mean": -18.4, + "lo": -20.5, + "hi": -16.4 + }, + "rounds": { + "mean": 1.6, + "lo": 1.3, + "hi": 1.9 + } + } + } + }, + "laterRun": { + "seeds": 20, + "half": 711, + "kept": 40, + "arms": { + "today": { + "found10": 4.85, + "found25": 10.15, + "found50": 20.4, + "spent": 70.3 + }, + "fresh": { + "found10": 4.4, + "found25": 15.9, + "found50": 38.9, + "spent": 38.1 + }, + "seeded": { + "found10": 9.55, + "found25": 23.9, + "found50": 47.65, + "spent": 30 + } + }, + "seededMinusFresh": { + "found10": { + "mean": 5.15, + "lo": 4.6, + "hi": 5.65 + }, + "found25": { + "mean": 8, + "lo": 7.2, + "hi": 8.85 + }, + "found50": { + "mean": 8.75, + "lo": 7.65, + "hi": 9.85 + }, + "spent": { + "mean": -8.1, + "lo": -9.1, + "hi": -7 + } + } + } + }, + "gemini-embedding-001@768": { + "segment": "brreg-breweries", + "briefLanguage": "en", + "judge": "gemini-3.8-flash-fast", + "companies": 1422, + "agreement": { + "judgedYes": 225, + "registerGood": 233, + "both": 206, + "judgeOnly": 19, + "registerOnly": 27, + "agree": 0.968 + }, + "stability": { + "asked": 200, + "changed": 3 + }, + "judged": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "en", + "candidates": 1138, + "good": 225, + "arms": { + "today": { + "found25": 24.55, + "found50": 47, + "found100": 91.85, + "found200": 157.25, + "checksTo25": 25.45, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 24.55, + "found50": 47, + "found100": 91.85, + "found200": 157.25, + "checksTo25": 25.45, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 23.95, + "found50": 47.9, + "found100": 95.25, + "found200": 172.35, + "checksTo25": 26.1, + "spent": 30, + "rounds": 3 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 24.55, + "lo": 24.35, + "hi": 24.75 + }, + "found50": { + "mean": 47, + "lo": 46.7, + "hi": 47.3 + }, + "found100": { + "mean": 91.85, + "lo": 91.25, + "hi": 92.45 + }, + "found200": { + "mean": 157.25, + "lo": 155.35, + "hi": 159.1 + }, + "checksTo25": { + "mean": 25.45, + "lo": 25.25, + "hi": 25.65 + }, + "spent": { + "mean": 50, + "lo": 50, + "hi": 50 + }, + "rounds": { + "mean": 1, + "lo": 1, + "hi": 1 + } + }, + "today-in-rounds": { + "found25": { + "mean": 24.55, + "lo": 24.35, + "hi": 24.75 + }, + "found50": { + "mean": 47, + "lo": 46.7, + "hi": 47.3 + }, + "found100": { + "mean": 91.85, + "lo": 91.25, + "hi": 92.45 + }, + "found200": { + "mean": 157.25, + "lo": 155.35, + "hi": 159.1 + }, + "checksTo25": { + "mean": 25.45, + "lo": 25.25, + "hi": 25.65 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + }, + "learner": { + "found25": { + "mean": 23.95, + "lo": 23.85, + "hi": 24 + }, + "found50": { + "mean": 47.9, + "lo": 47.7, + "hi": 48.15 + }, + "found100": { + "mean": 95.25, + "lo": 94.85, + "hi": 95.65 + }, + "found200": { + "mean": 172.35, + "lo": 170.4, + "hi": 174.2 + }, + "checksTo25": { + "mean": 26.1, + "lo": 26, + "hi": 26.25 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + }, + "learner": { + "found25": { + "mean": -0.6, + "lo": -0.85, + "hi": -0.35 + }, + "found50": { + "mean": 0.9, + "lo": 0.45, + "hi": 1.4 + }, + "found100": { + "mean": 3.4, + "lo": 2.75, + "hi": 4.05 + }, + "found200": { + "mean": 15.1, + "lo": 14.4, + "hi": 15.85 + }, + "checksTo25": { + "mean": 0.65, + "lo": 0.4, + "hi": 0.9 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + } + } + }, + "register": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "en", + "candidates": 1138, + "good": 233, + "arms": { + "today": { + "found25": 25, + "found50": 47.8, + "found100": 92, + "found200": 154.6, + "checksTo25": 25, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 25, + "found50": 47.8, + "found100": 92, + "found200": 154.6, + "checksTo25": 25, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 23.6, + "found50": 47.1, + "found100": 94.7, + "found200": 166.7, + "checksTo25": 26.5, + "spent": 30, + "rounds": 3 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 25, + "lo": 25, + "hi": 25 + }, + "found50": { + "mean": 47.8, + "lo": 47.55, + "hi": 48.05 + }, + "found100": { + "mean": 92, + "lo": 91.5, + "hi": 92.55 + }, + "found200": { + "mean": 154.6, + "lo": 152.65, + "hi": 156.45 + }, + "checksTo25": { + "mean": 25, + "lo": 25, + "hi": 25 + }, + "spent": { + "mean": 50, + "lo": 50, + "hi": 50 + }, + "rounds": { + "mean": 1, + "lo": 1, + "hi": 1 + } + }, + "today-in-rounds": { + "found25": { + "mean": 25, + "lo": 25, + "hi": 25 + }, + "found50": { + "mean": 47.8, + "lo": 47.55, + "hi": 48.05 + }, + "found100": { + "mean": 92, + "lo": 91.5, + "hi": 92.55 + }, + "found200": { + "mean": 154.6, + "lo": 152.65, + "hi": 156.45 + }, + "checksTo25": { + "mean": 25, + "lo": 25, + "hi": 25 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + }, + "learner": { + "found25": { + "mean": 23.6, + "lo": 23.35, + "hi": 23.85 + }, + "found50": { + "mean": 47.1, + "lo": 46.75, + "hi": 47.5 + }, + "found100": { + "mean": 94.7, + "lo": 94.2, + "hi": 95.25 + }, + "found200": { + "mean": 166.7, + "lo": 164.85, + "hi": 168.4 + }, + "checksTo25": { + "mean": 26.5, + "lo": 26.25, + "hi": 26.75 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + }, + "learner": { + "found25": { + "mean": -1.4, + "lo": -1.65, + "hi": -1.15 + }, + "found50": { + "mean": -0.7, + "lo": -1.05, + "hi": -0.35 + }, + "found100": { + "mean": 2.7, + "lo": 2, + "hi": 3.4 + }, + "found200": { + "mean": 12.1, + "lo": 11.45, + "hi": 12.75 + }, + "checksTo25": { + "mean": 1.5, + "lo": 1.25, + "hi": 1.75 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + } + } + }, + "laterRun": { + "seeds": 20, + "half": 711, + "kept": 30, + "arms": { + "today": { + "found10": 10, + "found25": 24.35, + "found50": 46.5, + "spent": 50 + }, + "fresh": { + "found10": 8.95, + "found25": 23.4, + "found50": 47, + "spent": 30 + }, + "seeded": { + "found10": 9.95, + "found25": 24.65, + "found50": 48.9, + "spent": 30 + } + }, + "seededMinusFresh": { + "found10": { + "mean": 1, + "lo": 0.75, + "hi": 1.25 + }, + "found25": { + "mean": 1.25, + "lo": 0.9, + "hi": 1.55 + }, + "found50": { + "mean": 1.9, + "lo": 1.3, + "hi": 2.4 + }, + "spent": { + "mean": 0, + "lo": 0, + "hi": 0 + } + } + } + }, + "text-embedding-3-large@1536": { + "segment": "brreg-breweries", + "briefLanguage": "en", + "judge": "gemini-3.8-flash-fast", + "companies": 1422, + "agreement": { + "judgedYes": 225, + "registerGood": 233, + "both": 206, + "judgeOnly": 19, + "registerOnly": 27, + "agree": 0.968 + }, + "stability": { + "asked": 200, + "changed": 3 + }, + "judged": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "en", + "candidates": 1138, + "good": 225, + "arms": { + "today": { + "found25": 21.65, + "found50": 44.85, + "found100": 81.4, + "found200": 146.6, + "checksTo25": 28.85, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 21.65, + "found50": 44.85, + "found100": 81.4, + "found200": 146.6, + "checksTo25": 28.85, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 21.3, + "found50": 45, + "found100": 92.4, + "found200": 171.15, + "checksTo25": 28.85, + "spent": 30, + "rounds": 3 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 21.65, + "lo": 21.3, + "hi": 22 + }, + "found50": { + "mean": 44.85, + "lo": 44.4, + "hi": 45.3 + }, + "found100": { + "mean": 81.4, + "lo": 80.35, + "hi": 82.35 + }, + "found200": { + "mean": 146.6, + "lo": 144.6, + "hi": 148.45 + }, + "checksTo25": { + "mean": 28.85, + "lo": 28.45, + "hi": 29.2 + }, + "spent": { + "mean": 50, + "lo": 50, + "hi": 50 + }, + "rounds": { + "mean": 1, + "lo": 1, + "hi": 1 + } + }, + "today-in-rounds": { + "found25": { + "mean": 21.65, + "lo": 21.3, + "hi": 22 + }, + "found50": { + "mean": 44.85, + "lo": 44.4, + "hi": 45.3 + }, + "found100": { + "mean": 81.4, + "lo": 80.35, + "hi": 82.35 + }, + "found200": { + "mean": 146.6, + "lo": 144.6, + "hi": 148.45 + }, + "checksTo25": { + "mean": 28.85, + "lo": 28.45, + "hi": 29.2 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + }, + "learner": { + "found25": { + "mean": 21.3, + "lo": 20.9, + "hi": 21.7 + }, + "found50": { + "mean": 45, + "lo": 44.55, + "hi": 45.45 + }, + "found100": { + "mean": 92.4, + "lo": 91.8, + "hi": 93 + }, + "found200": { + "mean": 171.15, + "lo": 169, + "hi": 173 + }, + "checksTo25": { + "mean": 28.85, + "lo": 28.45, + "hi": 29.25 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + }, + "learner": { + "found25": { + "mean": -0.35, + "lo": -0.65, + "hi": -0.05 + }, + "found50": { + "mean": 0.15, + "lo": -0.3, + "hi": 0.65 + }, + "found100": { + "mean": 11, + "lo": 10.1, + "hi": 11.85 + }, + "found200": { + "mean": 24.55, + "lo": 23.6, + "hi": 25.5 + }, + "checksTo25": { + "mean": 0, + "lo": -0.3, + "hi": 0.3 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + } + } + }, + "register": { + "seeds": 20, + "perSegment": [ + { + "segment": "brreg-breweries", + "pool": "brreg-drinks", + "briefLanguage": "en", + "candidates": 1138, + "good": 233, + "arms": { + "today": { + "found25": 21.8, + "found50": 45.45, + "found100": 82.15, + "found200": 141.35, + "checksTo25": 28.2, + "spent": 50, + "rounds": 1 + }, + "today-in-rounds": { + "found25": 21.8, + "found50": 45.45, + "found100": 82.15, + "found200": 141.35, + "checksTo25": 28.2, + "spent": 30, + "rounds": 3 + }, + "learner": { + "found25": 21.5, + "found50": 44.85, + "found100": 91.8, + "found200": 165.9, + "checksTo25": 28.5, + "spent": 30, + "rounds": 3 + } + } + } + ], + "overall": { + "today": { + "found25": { + "mean": 21.8, + "lo": 21.6, + "hi": 22 + }, + "found50": { + "mean": 45.45, + "lo": 45.2, + "hi": 45.7 + }, + "found100": { + "mean": 82.15, + "lo": 81.35, + "hi": 83 + }, + "found200": { + "mean": 141.35, + "lo": 139.6, + "hi": 143 + }, + "checksTo25": { + "mean": 28.2, + "lo": 28, + "hi": 28.4 + }, + "spent": { + "mean": 50, + "lo": 50, + "hi": 50 + }, + "rounds": { + "mean": 1, + "lo": 1, + "hi": 1 + } + }, + "today-in-rounds": { + "found25": { + "mean": 21.8, + "lo": 21.6, + "hi": 22 + }, + "found50": { + "mean": 45.45, + "lo": 45.2, + "hi": 45.7 + }, + "found100": { + "mean": 82.15, + "lo": 81.35, + "hi": 83 + }, + "found200": { + "mean": 141.35, + "lo": 139.6, + "hi": 143 + }, + "checksTo25": { + "mean": 28.2, + "lo": 28, + "hi": 28.4 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + }, + "learner": { + "found25": { + "mean": 21.5, + "lo": 21.1, + "hi": 21.9 + }, + "found50": { + "mean": 44.85, + "lo": 44.25, + "hi": 45.5 + }, + "found100": { + "mean": 91.8, + "lo": 91.05, + "hi": 92.5 + }, + "found200": { + "mean": 165.9, + "lo": 163.85, + "hi": 167.7 + }, + "checksTo25": { + "mean": 28.5, + "lo": 28.1, + "hi": 28.9 + }, + "spent": { + "mean": 30, + "lo": 30, + "hi": 30 + }, + "rounds": { + "mean": 3, + "lo": 3, + "hi": 3 + } + } + }, + "vsToday": { + "today-in-rounds": { + "found25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found50": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found100": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "found200": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "checksTo25": { + "mean": 0, + "lo": 0, + "hi": 0 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + }, + "learner": { + "found25": { + "mean": -0.3, + "lo": -0.65, + "hi": 0.05 + }, + "found50": { + "mean": -0.6, + "lo": -1.2, + "hi": 0 + }, + "found100": { + "mean": 9.65, + "lo": 8.65, + "hi": 10.6 + }, + "found200": { + "mean": 24.55, + "lo": 23.65, + "hi": 25.5 + }, + "checksTo25": { + "mean": 0.3, + "lo": -0.05, + "hi": 0.65 + }, + "spent": { + "mean": -20, + "lo": -20, + "hi": -20 + }, + "rounds": { + "mean": 2, + "lo": 2, + "hi": 2 + } + } + } + }, + "laterRun": { + "seeds": 20, + "half": 711, + "kept": 30.2, + "arms": { + "today": { + "found10": 8.3, + "found25": 22.15, + "found50": 43.65, + "spent": 50 + }, + "fresh": { + "found10": 7.7, + "found25": 21.25, + "found50": 44.75, + "spent": 30.4 + }, + "seeded": { + "found10": 9.95, + "found25": 24.05, + "found50": 47.45, + "spent": 30 + } + }, + "seededMinusFresh": { + "found10": { + "mean": 2.25, + "lo": 1.9, + "hi": 2.6 + }, + "found25": { + "mean": 2.8, + "lo": 2.1, + "hi": 3.45 + }, + "found50": { + "mean": 2.7, + "lo": 1.95, + "hi": 3.5 + }, + "spent": { + "mean": -0.4, + "lo": -0.9, + "hi": 0 + } + } + } + } + } +} diff --git a/pipelines/src/distribution/db.ts b/pipelines/src/distribution/db.ts index f70b76ee9..16abc1525 100644 --- a/pipelines/src/distribution/db.ts +++ b/pipelines/src/distribution/db.ts @@ -16,6 +16,7 @@ import { normalizeDomain, normalizeOrgName } from "@launchstack/tools/org-resolv import { dealStageHistory, distributionAgreements, + distributionFitVerdicts, distributionPrograms, distributionRuns, partnerEvidence, @@ -30,8 +31,10 @@ import { type PartnerRelationshipRow, type RelationshipEventRow, } from "./schema"; +import { companyText } from "./semantic"; import { assertTransition, + fitDecision, IN_MOTION_STAGES, isPastCandidate, STALE_AFTER_DAYS, @@ -931,6 +934,178 @@ export async function listWonDomains( ); } +// ─── Fit verdicts ──────────────────────────────────────────────────────────── + +export interface FitVerdictInput { + resolveKey: string; + name: string; + /** The company's listing in its own words (./semantic's companyText), as a ranking reads it. */ + text: string; + fit: boolean; + reason?: string | null; +} + +/** + * Keep what the fit check said, one row per company and segment; the newest + * verdict replaces the one before it. What research found outranks a look at + * the listing: a later listing verdict for the same segment leaves a research + * verdict in place. + */ +export async function saveFitVerdicts(args: { + companyId: bigint; + programId: string; + runId: string | null; + basis: "listing" | "research"; + /** ./shortlist's segmentKey of what the run asked the fit check. */ + segmentKey: string; + verdicts: readonly FitVerdictInput[]; +}): Promise { + // One statement may not touch a row twice: the last verdict on a company wins. + const byKey = new Map(args.verdicts.map(v => [v.resolveKey, v])); + if (byKey.size === 0) return; + const db = getDb(); + const judgedAt = new Date(); + const rows = [...byKey.values()].map(v => ({ + companyId: args.companyId, + programId: args.programId, + resolveKey: v.resolveKey, + name: v.name.slice(0, 512), + text: v.text.slice(0, 2_000), + fit: v.fit, + reason: v.reason ? v.reason.slice(0, 600) : null, + basis: args.basis, + segmentKey: args.segmentKey, + runId: args.runId, + judgedAt, + })); + const CHUNK = 200; + for (let i = 0; i < rows.length; i += CHUNK) { + await db + .insert(distributionFitVerdicts) + .values(rows.slice(i, i + CHUNK)) + .onConflictDoUpdate({ + target: [ + distributionFitVerdicts.companyId, + distributionFitVerdicts.programId, + distributionFitVerdicts.resolveKey, + ], + set: { + name: sql`excluded.name`, + text: sql`excluded.text`, + fit: sql`excluded.fit`, + reason: sql`excluded.reason`, + basis: sql`excluded.basis`, + segmentKey: sql`excluded.segment_key`, + runId: sql`excluded.run_id`, + judgedAt: sql`excluded.judged_at`, + }, + setWhere: sql`not (${distributionFitVerdicts.basis} = 'research' and excluded.basis = 'listing' and ${distributionFitVerdicts.segmentKey} = excluded.segment_key)`, + }); + } +} + +/** A verdict a run starts from. */ +export interface FitExample { + resolveKey: string; + /** The company's listing in its own words. */ + text: string; + good: boolean; + /** Whose verdict: a person's handling of the deal, or the fit check's. */ + source: "person" | "research" | "listing"; +} + +/** + * Verdicts one run reads: enough to learn from, bounded so a run's start stays + * a handful of embedding calls (./semantic embeds 64 texts a call, so seven). + */ +const FIT_EXAMPLES = 400; + +/** + * What is already known about who fits a segment, for the next run's ranking + * to start from: people's own decisions on its deals (qualified, pursued or + * won is a yes; not a fit is a no), then the fit check's stored verdicts for + * the question this run asks, newest first. A person's decision replaces the + * fit check's on the same company, and counts whatever the segment said when + * it was made: a person judged the company, not a wording. + */ +export async function listFitExamples(args: { + companyId: bigint; + programId: string; + /** + * ./shortlist's segmentKey of what the run asks: the fit check's verdicts + * on another wording, area or kind of buyer are left out. + */ + segmentKey: string; + limit?: number; +}): Promise { + const limit = args.limit ?? FIT_EXAMPLES; + const db = getDb(); + const deals = await db + .select({ + stage: partnerRelationships.stage, + resolveKey: partnerOrgs.resolveKey, + name: partnerOrgs.name, + categories: partnerOrgs.categories, + description: partnerOrgs.description, + }) + .from(partnerRelationships) + .innerJoin(partnerOrgs, eq(partnerOrgs.id, partnerRelationships.orgId)) + .where( + and( + eq(partnerRelationships.companyId, args.companyId), + eq(partnerRelationships.programId, args.programId) + ) + ) + .orderBy(desc(partnerRelationships.stageChangedAt)); + const out = new Map(); + for (const row of deals) { + const good = fitDecision(row.stage); + // An organisation with deals in two kinds: its most recently moved one speaks. + if (good === null || out.has(row.resolveKey)) continue; + if (out.size >= limit) break; + out.set(row.resolveKey, { + resolveKey: row.resolveKey, + text: companyText({ + name: row.name, + categories: row.categories ?? [], + description: row.description, + }), + good, + source: "person", + }); + } + if (out.size < limit) { + const stored = await db + .select({ + resolveKey: distributionFitVerdicts.resolveKey, + text: distributionFitVerdicts.text, + fit: distributionFitVerdicts.fit, + basis: distributionFitVerdicts.basis, + }) + .from(distributionFitVerdicts) + .where( + and( + eq(distributionFitVerdicts.companyId, args.companyId), + eq(distributionFitVerdicts.programId, args.programId), + eq(distributionFitVerdicts.segmentKey, args.segmentKey) + ) + ) + .orderBy(desc(distributionFitVerdicts.judgedAt), desc(distributionFitVerdicts.id)) + .limit(limit); + for (const row of stored) { + if (out.size >= limit) break; + if (out.has(row.resolveKey)) continue; + out.set(row.resolveKey, { + resolveKey: row.resolveKey, + text: row.text, + good: row.fit, + source: row.basis, + }); + } + } + return [...out.values()]; +} + // ─── Events and transitions ────────────────────────────────────────────────── export async function addEvent(args: { diff --git a/pipelines/src/distribution/index.ts b/pipelines/src/distribution/index.ts index 567af70af..f0c1202d2 100644 --- a/pipelines/src/distribution/index.ts +++ b/pipelines/src/distribution/index.ts @@ -12,6 +12,8 @@ export * from "./plan"; export * from "./gather"; export * from "./score"; export * from "./semantic"; +export * from "./learn"; +export * from "./shortlist"; export * from "./geocode"; export * from "./judge"; export * from "./render"; diff --git a/pipelines/src/distribution/learn.test.ts b/pipelines/src/distribution/learn.test.ts new file mode 100644 index 000000000..75a86f185 --- /dev/null +++ b/pipelines/src/distribution/learn.test.ts @@ -0,0 +1,400 @@ +import { describe, expect, it } from "vitest"; + +import { + createShortlistLearner, + learnerOverFeatures, + LEARNER_SETTINGS, + type LearnerSettings, +} from "./learn"; + +/** A small fixed stream of numbers in [0, 1). */ +function stream(seed: number): () => number { + let state = seed >>> 0; + return () => { + state = (Math.imul(state, 1664525) + 1013904223) >>> 0; + return state / 4294967296; + }; +} + +/** + * Two kinds of company in a 12-dimensional embedding: the first `a` sit around + * one direction, the rest around another. Relevance says nothing about which + * kind a company is. + */ +function twoKinds(a: number, b: number, seed = 7) { + const next = stream(seed); + const d = 12; + const vectors: number[][] = []; + for (let i = 0; i < a + b; i++) { + const v = Array.from({ length: d }, () => (next() - 0.5) * 0.4); + v[i < a ? 0 : 1]! += 1; + vectors.push(v); + } + const relevance = vectors.map(() => 0.2 + (next() - 0.5) * 0.02); + return { vectors, relevance, d }; +} + +/** The posterior by the textbook formula, for comparison: mean and covariance. */ +function closedForm( + rows: number[][], + labels: number[], + settings: LearnerSettings, + p = rows[0]!.length +): { mean: number[]; cov: number[][] } { + const dims = p - 2; + const priorVar = (c: number): number => + c < dims + ? settings.priorSdProjection ** 2 + : c === dims + ? settings.priorSdScore ** 2 + : settings.priorSdBias ** 2; + const noiseSq = settings.noiseSd ** 2; + // Precision = prior precision + Σ f fᵀ / noise². + const precision = Array.from({ length: p }, (_, r) => + Array.from({ length: p }, (_, c) => (r === c ? 1 / priorVar(c) : 0)) + ); + const evidence = Array.from({ length: p }, (_, c) => (c === dims ? 1 / priorVar(c) : 0)); + for (const [i, f] of rows.entries()) { + for (let r = 0; r < p; r++) { + for (let c = 0; c < p; c++) precision[r]![c]! += (f[r]! * f[c]!) / noiseSq; + evidence[r]! += (f[r]! * labels[i]!) / noiseSq; + } + } + // Invert by Gauss–Jordan. + const a = precision.map((row, r) => [...row, ...row.map((_, c) => (r === c ? 1 : 0))]); + for (let col = 0; col < p; col++) { + let pivot = col; + for (let r = col + 1; r < p; r++) + if (Math.abs(a[r]![col]!) > Math.abs(a[pivot]![col]!)) pivot = r; + [a[col], a[pivot]] = [a[pivot]!, a[col]!]; + const scale = a[col]![col]!; + for (let c = 0; c < 2 * p; c++) a[col]![c]! /= scale; + for (let r = 0; r < p; r++) { + if (r === col) continue; + const factor = a[r]![col]!; + for (let c = 0; c < 2 * p; c++) a[r]![c]! -= factor * a[col]![c]!; + } + } + const cov = a.map(row => row.slice(p)); + const mean = cov.map(row => row.reduce((sum, v, c) => sum + v * evidence[c]!, 0)); + return { mean, cov }; +} + +describe("shortlist learner", () => { + it("predicts the relevance itself before any verdict", async () => { + const { vectors, relevance } = twoKinds(6, 6); + const learner = await createShortlistLearner({ vectors, relevance }); + expect(learner.predicted()).toEqual(relevance); + expect(learner.learnedFrom).toBe(0); + }); + + it("with no bonus and no verdicts, checks in the fixed ranking's order", async () => { + const { vectors } = twoKinds(5, 5); + const relevance = [0.1, 0.9, 0.3, 0.3, 0.8, -0.2, 0.5, 0.0, 0.7, 0.6]; + const learner = await createShortlistLearner({ + vectors, + relevance, + settings: { bonus: 0 }, + }); + // 0.3 twice: the earlier candidate (2) goes first. + expect(learner.next(10)).toEqual([1, 4, 8, 9, 6, 2, 3, 0, 7, 5]); + expect(learner.next(3)).toEqual([]); + }); + + it("moves the kind that was judged good up, and the kind judged bad down", async () => { + const { vectors, relevance } = twoKinds(20, 20); + const learner = await createShortlistLearner({ vectors, relevance }); + // Four verdicts: the first kind fits, the second does not. + learner.observe(0, true); + learner.observe(1, true); + learner.observe(20, false); + learner.observe(21, false); + const picked = learner.next(10); + expect(picked).toHaveLength(10); + expect(picked.every(j => j < 20)).toBe(true); + const predicted = learner.predicted(); + const mean = (from: number, to: number): number => + predicted.slice(from, to).reduce((s, v) => s + v, 0) / (to - from); + expect(mean(2, 20)).toBeGreaterThan(mean(22, 40) + 0.2); + expect(learner.learnedFrom).toBe(4); + }); + + it("never returns a candidate twice and keeps to the candidates it may choose among", async () => { + const { vectors, relevance } = twoKinds(8, 8); + const learner = await createShortlistLearner({ vectors, relevance }); + const even = learner.next(5, j => j % 2 === 0); + expect(even.every(j => j % 2 === 0)).toBe(true); + const rest = learner.next(100); + expect(new Set([...even, ...rest]).size).toBe(16); + expect(learner.next(1)).toEqual([]); + }); + + it("gives the same picks for the same companies", async () => { + const { vectors, relevance } = twoKinds(15, 25, 11); + const run = async (): Promise => { + const learner = await createShortlistLearner({ vectors, relevance }); + const order: number[] = []; + for (let round = 0; round < 4; round++) { + const batch = learner.next(5); + for (const j of batch) learner.observe(j, j < 15); + order.push(...batch); + } + return order; + }; + expect(await run()).toEqual(await run()); + }); + + it("starts a later run from earlier verdicts as if it had seen them itself", async () => { + const { vectors, relevance } = twoKinds(12, 12, 3); + // Run A learns four verdicts itself. + const a = await createShortlistLearner({ vectors, relevance }); + for (const [j, good] of [ + [0, true], + [1, true], + [12, false], + [13, false], + ] as const) + a.observe(j, good); + // Run B is told the same four as earlier verdicts; the same companies are candidates again. + const b = await createShortlistLearner({ + vectors, + relevance, + earlier: [0, 1, 12, 13].map(j => ({ + vector: vectors[j]!, + relevance: relevance[j]!, + good: j < 12, + })), + }); + expect(b.learnedFrom).toBe(4); + // B's directions come from 28 rows (four of them twice), so the two are + // close, not equal: the same kind leads in both. + const top = (learner: typeof a): number[] => { + const predicted = learner.predicted(); + return predicted + .map((value, j) => ({ value, j })) + .filter(({ j }) => ![0, 1, 12, 13].includes(j)) + .sort((x, y) => y.value - x.value) + .slice(0, 10) + .map(({ j }) => j); + }; + expect(top(a).every(j => j < 12)).toBe(true); + expect(top(b).every(j => j < 12)).toBe(true); + }); + + it("leaves out an earlier verdict whose embedding is another model's", async () => { + const { vectors, relevance } = twoKinds(4, 4); + const learner = await createShortlistLearner({ + vectors, + relevance, + earlier: [{ vector: [1, 0, 0], relevance: 0.5, good: true }], + }); + expect(learner.learnedFrom).toBe(0); + expect(learner.predicted()).toEqual(relevance); + }); + + it("leaves out an earlier verdict that holds something that is not a number", async () => { + const { vectors, relevance } = twoKinds(6, 6); + const d = vectors[0]!.length; + const sound = { vector: vectors[7]!, relevance: 0.2, good: true }; + const learner = await createShortlistLearner({ + vectors, + relevance, + earlier: [ + { + vector: Array.from({ length: d }, (_, a) => (a === 2 ? NaN : 0.1)), + relevance: 0.3, + good: false, + }, + { vector: Array.from({ length: d }, () => Infinity), relevance: 0.3, good: true }, + { vector: vectors[0]!, relevance: NaN, good: false }, + sound, + ], + }); + // Only the sound one counts, and every candidate can still be ranked. + expect(learner.learnedFrom).toBe(1); + expect(learner.predicted().every(Number.isFinite)).toBe(true); + expect(learner.next(vectors.length)).toHaveLength(vectors.length); + + const alone = await createShortlistLearner({ vectors, relevance, earlier: [sound] }); + expect(learner.predicted()).toEqual(alone.predicted()); + }); + + it("refuses a candidate whose embedding or relevance is not a number", async () => { + const { vectors, relevance } = twoKinds(3, 3); + const broken = vectors.map((v, j) => (j === 4 ? v.map((x, a) => (a === 0 ? NaN : x)) : v)); + await expect(createShortlistLearner({ vectors: broken, relevance })).rejects.toThrow( + /not a number/ + ); + await expect( + createShortlistLearner({ + vectors, + relevance: relevance.map((r, j) => (j === 1 ? Number.NaN : r)), + }) + ).rejects.toThrow(/not a number/); + }); + + it("works on one candidate and on none", async () => { + const one = await createShortlistLearner({ vectors: [[1, 0, 0]], relevance: [0.4] }); + expect(one.next(3)).toEqual([0]); + one.observe(0, true); + expect(one.next(3)).toEqual([]); + const none = await createShortlistLearner({ vectors: [], relevance: [] }); + expect(none.size).toBe(0); + expect(none.next(3)).toEqual([]); + expect(none.predicted()).toEqual([]); + }); + + it("refuses embeddings of different sizes", async () => { + await expect( + createShortlistLearner({ + vectors: [ + [1, 0], + [1, 0, 0], + ], + relevance: [0.1, 0.2], + }) + ).rejects.toThrow(/different sizes/); + }); +}); + +describe("the model behind the learner", () => { + const settings: LearnerSettings = { ...LEARNER_SETTINGS }; + const p = 5; // three directions, relevance, intercept + const next = stream(21); + const rows = Array.from({ length: 30 }, () => [ + (next() - 0.5) * 2, + (next() - 0.5) * 2, + (next() - 0.5) * 2, + next() * 0.6 - 0.1, + 1, + ]); + const features = Float64Array.from(rows.flat()); + const labelOf = (j: number): boolean => rows[j]![0]! + rows[j]![3]! > 0.3; + + /** f_jᵀ · cov · f_j */ + const varianceOf = (cov: number[][], j: number): number => + rows[j]!.reduce( + (sum, fr, r) => sum + fr * cov[r]!.reduce((s, v, c) => s + v * rows[j]![c]!, 0), + 0 + ); + + it("matches the textbook posterior after a run of verdicts", () => { + const learner = learnerOverFeatures({ features, p, candidates: 30, settings }); + const seen: number[] = []; + for (let round = 0; round < 4; round++) { + const batch = learner.next(3); + for (const j of batch) learner.observe(j, labelOf(j)); + seen.push(...batch); + } + const exact = closedForm( + seen.map(j => rows[j]!), + seen.map(j => (labelOf(j) ? 1 : 0)), + settings + ); + const predicted = learner.predicted(); + for (let j = 0; j < 30; j++) { + const want = rows[j]!.reduce((sum, v, c) => sum + v * exact.mean[c]!, 0); + expect(predicted[j]).toBeCloseTo(want, 9); + } + }); + + it("picks by predicted fit plus the bonus on what is still uncertain", () => { + const learner = learnerOverFeatures({ features, p, candidates: 30, settings }); + const seen = learner.next(4); + for (const j of seen) learner.observe(j, labelOf(j)); + const exact = closedForm( + seen.map(j => rows[j]!), + seen.map(j => (labelOf(j) ? 1 : 0)), + settings + ); + let best = -1; + let bestScore = -Infinity; + for (let j = 0; j < 30; j++) { + if (seen.includes(j)) continue; + const mean = rows[j]!.reduce((sum, v, c) => sum + v * exact.mean[c]!, 0); + const score = mean + settings.bonus * Math.sqrt(varianceOf(exact.cov, j)); + if (score > bestScore) { + bestScore = score; + best = j; + } + } + expect(learner.next(1)).toEqual([best]); + }); + + it("inside a batch, each pick lowers the bonus of companies like it", () => { + const optimistic = { ...settings, bonus: 5 }; + const together = learnerOverFeatures({ + features, + p, + candidates: 30, + settings: optimistic, + }); + const batch = together.next(3); + // The same three, picked one at a time with the model told about each pick. + const oneByOne: number[] = []; + const taken: number[] = []; + for (let i = 0; i < 3; i++) { + const exact = closedForm( + taken.map(j => rows[j]!), + taken.map(() => 0), + optimistic, + p + ); + // The mean is not refreshed inside a batch: it is still the prior's. + let best = -1; + let bestScore = -Infinity; + for (let j = 0; j < 30; j++) { + if (taken.includes(j)) continue; + const score = rows[j]![3]! + optimistic.bonus * Math.sqrt(varianceOf(exact.cov, j)); + if (score > bestScore) { + bestScore = score; + best = j; + } + } + oneByOne.push(best); + taken.push(best); + } + expect(batch).toEqual(oneByOne); + }); + + it("a picked company that was never judged teaches nothing", () => { + const withSkip = learnerOverFeatures({ features, p, candidates: 30, settings }); + const batch = withSkip.next(3); + withSkip.observe(batch[0]!, true); + withSkip.skip(batch[1]!); + withSkip.observe(batch[2]!, false); + // The same two verdicts, and the skipped company never picked. + const exact = closedForm([rows[batch[0]!]!, rows[batch[2]!]!], [1, 0], settings); + const predicted = withSkip.predicted(); + for (let j = 0; j < 30; j++) { + const want = rows[j]!.reduce((sum, v, c) => sum + v * exact.mean[c]!, 0); + expect(predicted[j]).toBeCloseTo(want, 9); + } + expect(withSkip.learnedFrom).toBe(2); + // It is not offered again. + expect(withSkip.next(30)).not.toContain(batch[1]); + }); + + it("counts earlier verdicts like verdicts of its own", () => { + const earlierRows = [3, 9, 17, 22]; + const stacked = Float64Array.from([...rows, ...earlierRows.map(j => rows[j]!)].flat()); + const seeded = learnerOverFeatures({ + features: stacked, + p, + candidates: 30, + earlierGood: earlierRows.map(labelOf), + settings, + }); + const exact = closedForm( + earlierRows.map(j => rows[j]!), + earlierRows.map(j => (labelOf(j) ? 1 : 0)), + settings + ); + const predicted = seeded.predicted(); + for (let j = 0; j < 30; j++) { + const want = rows[j]!.reduce((sum, v, c) => sum + v * exact.mean[c]!, 0); + expect(predicted[j]).toBeCloseTo(want, 9); + } + expect(seeded.learnedFrom).toBe(4); + }); +}); diff --git a/pipelines/src/distribution/learn.ts b/pipelines/src/distribution/learn.ts new file mode 100644 index 000000000..8b7ed4c9f --- /dev/null +++ b/pipelines/src/distribution/learn.ts @@ -0,0 +1,506 @@ +/** + * Whom to check next: a shortlist that learns from each verdict. + * + * The fixed ranking is a company's relevance to the segment's brief + * (./semantic), checked from the top down; no verdict changes who is checked + * next. Here every verdict does: the fit check's during a run, and the ones + * kept from earlier runs and from people's own decisions (won, not a fit). + * + * The model is a Bayesian linear regression of the verdict on three things: + * where the company's embedding sits along the main directions in which this + * run's companies differ from each other, its relevance to the brief, and an + * intercept. Its prior is "the relevance, as it is": before any verdict it + * predicts exactly the fixed ranking. The company checked next is the one with + * the highest predicted fit plus a bonus for how unsure the model still is + * about it (LinUCB), so a kind of company nobody has checked yet gets a look + * before the list settles on what it already knows. + * + * Measured in pipelines/experiments/company-search (E4 for the choice, + * production-replay for this code): over seven pools it finds 15 to 21 more + * good companies in 100 checks than the fixed ranking, depending on the + * embedding model. Where the fixed ranking already puts a good company at + * nearly every place it gives up a company or two in a hundred. Thompson + * sampling and checking the least certain company first found fewer in E4, so + * neither is offered here. The settings below are E4's: it tuned two of them + * on its two development segments (the prior spread of the direction weights + * and the bonus) and fixed the others by design. One is not E4's: the main + * directions are found in 6 passes where E4 makes 20, to keep a large run's + * arithmetic short. + */ + +export interface LearnerSettings { + /** Main directions of the companies' embeddings the model sees. */ + dims: number; + /** Assumed spread of a verdict (0 or 1) around the model's prediction. */ + noiseSd: number; + /** Prior spread of the weight on relevance, around 1. */ + priorSdScore: number; + /** Prior spread of the intercept, around 0. */ + priorSdBias: number; + /** Prior spread of the weights on the embedding's directions, around 0. */ + priorSdProjection: number; + /** Standard deviations of optimism added to the predicted fit. */ + bonus: number; + /** Passes of the search for the main directions. */ + rounds: number; +} + +export const LEARNER_SETTINGS: Readonly = { + dims: 48, + noiseSd: 0.5, + priorSdScore: 0.25, + priorSdBias: 1, + priorSdProjection: 0.4, + bonus: 0.5, + rounds: 6, +}; + +/** A verdict known before the run starts: an earlier run's, or a person's decision. */ +export interface EarlierVerdict { + /** The company's embedding, from the same model as the candidates'. */ + vector: readonly number[]; + /** Its relevance to this run's brief. */ + relevance: number; + good: boolean; +} + +export interface ShortlistLearner { + /** Candidates, in the order they were given. */ + readonly size: number; + /** Verdicts learned from so far, earlier ones included. */ + readonly learnedFrom: number; + /** + * The next candidates to check, best first: the highest predicted fit plus + * the uncertainty bonus. Never returns a candidate twice. `among` narrows + * the choice; fewer than `count` come back when fewer are left. + */ + next(count: number, among?: (index: number) => boolean): number[]; + /** The verdict on a candidate. */ + observe(index: number, good: boolean): void; + /** A candidate `next` returned that was never judged: it teaches nothing. */ + skip(index: number): void; + /** Predicted fit of every candidate from the verdicts so far; the relevance itself before any. */ + predicted(): number[]; +} + +// ── The model ─────────────────────────────────────────────────────────────── + +/** + * verdict ≈ theta · features + noise, with a Gaussian prior on theta. The + * posterior is exact and moves one company at a time: the covariance when a + * company is picked (it does not depend on the verdict), the evidence when + * its verdict arrives. + */ +class Posterior { + /** Posterior covariance, [p × p]. */ + readonly cov: Float64Array; + /** Prior precision · prior mean + Σ features · verdict / noise². */ + private readonly evidence: Float64Array; + private readonly noiseSq: number; + + constructor( + readonly p: number, + settings: LearnerSettings + ) { + const dims = p - 2; + this.cov = new Float64Array(p * p); + this.evidence = new Float64Array(p); + this.noiseSq = settings.noiseSd * settings.noiseSd; + for (let i = 0; i < dims; i++) + this.cov[i * p + i] = settings.priorSdProjection * settings.priorSdProjection; + this.cov[dims * p + dims] = settings.priorSdScore * settings.priorSdScore; + this.cov[(dims + 1) * p + dims + 1] = settings.priorSdBias * settings.priorSdBias; + // Prior mean: weight 1 on relevance, 0 elsewhere. + this.evidence[dims] = 1 / (settings.priorSdScore * settings.priorSdScore); + } + + /** cov · f, for the features starting at `at`. */ + private covTimes(features: Float64Array, at: number): Float64Array { + const { p, cov } = this; + const out = new Float64Array(p); + for (let r = 0; r < p; r++) { + const ro = r * p; + let sum = 0; + for (let c = 0; c < p; c++) sum += cov[ro + c]! * features[at + c]!; + out[r] = sum; + } + return out; + } + + /** + * The covariance after one more company is checked. Returns cov · f from + * before the update and the divisor, so a caller can move every other + * company's variance in one pass. + */ + shrink(features: Float64Array, at: number): { direction: Float64Array; divisor: number } { + const { p, cov } = this; + const u = this.covTimes(features, at); + let own = 0; + for (let c = 0; c < p; c++) own += features[at + c]! * u[c]!; + const divisor = this.noiseSq + own; + for (let r = 0; r < p; r++) { + const ur = u[r]! / divisor; + for (let c = 0; c < p; c++) cov[r * p + c]! -= ur * u[c]!; + } + return { direction: u, divisor }; + } + + /** + * Undo `shrink` for a company that was picked and never judged. Returns + * cov · f from before the update and the divisor, as `shrink` does. + */ + restore(features: Float64Array, at: number): { direction: Float64Array; divisor: number } { + const { p, cov } = this; + const u = this.covTimes(features, at); + let own = 0; + for (let c = 0; c < p; c++) own += features[at + c]! * u[c]!; + // Always positive: a checked company's variance is below the noise. + const divisor = Math.max(this.noiseSq - own, 1e-12); + for (let r = 0; r < p; r++) { + const ur = u[r]! / divisor; + for (let c = 0; c < p; c++) cov[r * p + c]! += ur * u[c]!; + } + return { direction: u, divisor }; + } + + /** Add a verdict to the evidence. A "no" adds nothing: its target is zero. */ + learn(features: Float64Array, at: number, good: boolean): void { + if (!good) return; + for (let c = 0; c < this.p; c++) this.evidence[c]! += features[at + c]! / this.noiseSq; + } + + /** Posterior mean of theta. */ + mean(): Float64Array { + const { p, cov, evidence } = this; + const out = new Float64Array(p); + for (let r = 0; r < p; r++) { + let sum = 0; + for (let c = 0; c < p; c++) sum += cov[r * p + c]! * evidence[c]!; + out[r] = sum; + } + return out; + } + + /** fᵀ · cov · f. */ + variance(features: Float64Array, at: number): number { + const u = this.covTimes(features, at); + let sum = 0; + for (let c = 0; c < this.p; c++) sum += features[at + c]! * u[c]!; + return sum; + } +} + +function dotRow(features: Float64Array, at: number, v: Float64Array): number { + let sum = 0; + for (let c = 0; c < v.length; c++) sum += features[at + c]! * v[c]!; + return sum; +} + +/** + * The learner over features that are already built: `rows` companies of `p` + * numbers each (the projected embedding, then relevance, then 1). The first + * `candidates` rows can be picked; the rest are earlier verdicts, whose labels + * are `earlierGood`. `createShortlistLearner` is the way in for production; + * this is the seam the experiment's checks compare against its own arithmetic. + */ +export function learnerOverFeatures(args: { + features: Float64Array; + p: number; + candidates: number; + earlierGood?: readonly boolean[]; + settings?: Partial; +}): ShortlistLearner { + const settings: LearnerSettings = { ...LEARNER_SETTINGS, ...args.settings }; + const { features, p, candidates: n } = args; + const earlierGood = args.earlierGood ?? []; + if (features.length !== (n + earlierGood.length) * p) + throw new Error("The learner's features do not match its companies"); + const model = new Posterior(p, settings); + const relevanceAt = p - 2; + + let learnedFrom = 0; + for (const [e, good] of earlierGood.entries()) { + const at = (n + e) * p; + model.shrink(features, at); + model.learn(features, at, good); + learnedFrom += 1; + } + + /** 0 open; 1 picked, verdict pending; 2 judged or set aside. */ + const state = new Uint8Array(n); + const variance = new Float64Array(n); + for (let j = 0; j < n; j++) variance[j] = model.variance(features, j * p); + const predicted = new Float64Array(n); + let stale = true; + + const refresh = (): void => { + if (!stale) return; + const theta = model.mean(); + for (let j = 0; j < n; j++) predicted[j] = dotRow(features, j * p, theta); + stale = false; + }; + + /** Move every open company's variance after the covariance moved along `direction`. */ + const moveVariances = (direction: Float64Array, divisor: number, sign: 1 | -1): void => { + for (let j = 0; j < n; j++) { + if (state[j] !== 0) continue; + const along = dotRow(features, j * p, direction); + variance[j]! += (sign * (along * along)) / divisor; + } + }; + + const take = (index: number): void => { + state[index] = 1; + const { direction, divisor } = model.shrink(features, index * p); + moveVariances(direction, divisor, -1); + }; + + return { + size: n, + get learnedFrom() { + return learnedFrom; + }, + next(count, among) { + refresh(); + const out: number[] = []; + for (let i = 0; i < count; i++) { + let best = -1; + let bestScore = -Infinity; + for (let j = 0; j < n; j++) { + if (state[j] !== 0 || (among && !among(j))) continue; + const score = + predicted[j]! + settings.bonus * Math.sqrt(Math.max(0, variance[j]!)); + // Strictly higher: among equals the earlier candidate wins. + if (score > bestScore) { + bestScore = score; + best = j; + } + } + if (best < 0) break; + out.push(best); + // Inside one batch the uncertainty moves after each pick, so a + // batch does not spend all its checks on the same unknown. + take(best); + } + return out; + }, + observe(index, good) { + if (index < 0 || index >= n) throw new Error("No such candidate"); + if (state[index] === 2) return; + if (state[index] === 0) take(index); + state[index] = 2; + model.learn(features, index * p, good); + learnedFrom += 1; + stale = true; + }, + skip(index) { + if (index < 0 || index >= n) throw new Error("No such candidate"); + if (state[index] !== 1) return; + state[index] = 2; + const { direction, divisor } = model.restore(features, index * p); + moveVariances(direction, divisor, 1); + stale = true; + }, + predicted() { + refresh(); + // Before any verdict the prediction is the relevance itself; say so + // exactly, without the rounding of a trip through the model. + if (learnedFrom === 0) + return Array.from({ length: n }, (_, j) => features[j * p + relevanceAt]!); + return Array.from(predicted); + }, + }; +} + +// ── From embeddings to features ───────────────────────────────────────────── + +/** A fixed stream of normal draws, so the same companies always give the same directions. */ +function normalDraws(seed: number): () => number { + let state = seed >>> 0; + const uniform = (): number => { + state = (state + 0x6d2b79f5) >>> 0; + let t = state; + t = Math.imul(t ^ (t >>> 15), t | 1); + t ^= t + Math.imul(t ^ (t >>> 7), t | 61); + return ((t ^ (t >>> 14)) >>> 0) / 4294967296; + }; + return () => + Math.sqrt(-2 * Math.log(Math.max(uniform(), 1e-12))) * Math.cos(2 * Math.PI * uniform()); +} + +/** Modified Gram–Schmidt on [k × d] rows, in place; a row with nothing left becomes zero. */ +function orthonormalise(rows: Float64Array, k: number, d: number): void { + for (let c = 0; c < k; c++) { + const co = c * d; + for (let prev = 0; prev < c; prev++) { + const po = prev * d; + let along = 0; + for (let a = 0; a < d; a++) along += rows[co + a]! * rows[po + a]!; + for (let a = 0; a < d; a++) rows[co + a]! -= along * rows[po + a]!; + } + let sq = 0; + for (let a = 0; a < d; a++) sq += rows[co + a]! * rows[co + a]!; + const scale = sq > 1e-18 ? 1 / Math.sqrt(sq) : 0; + for (let a = 0; a < d; a++) rows[co + a]! *= scale; + } +} + +/** + * Let the process serve something else between passes. Measured on made-up + * vectors: 500 companies take half a second in all, 5,000 at 1,536 dimensions + * under five seconds, and no single pass holds the process for more than half + * a second. + */ +const breathe = (): Promise => new Promise(resolve => setImmediate(resolve)); + +/** + * Each row of `unit` [m × d] on the `k` main directions of the rows about + * their mean, as [m × k]. Block power iteration on the rows themselves from a + * fixed start: what the model needs is the span of the leading directions, and + * a handful of passes finds it without ever building a d × d matrix. + */ +async function onMainDirections( + unit: Float32Array, + m: number, + d: number, + k: number, + rounds: number +): Promise { + const projected = new Float64Array(m * k); + if (k === 0 || m === 0) return projected; + const mean = new Float64Array(d); + for (let i = 0; i < m; i++) { + const io = i * d; + for (let a = 0; a < d; a++) mean[a]! += unit[io + a]!; + } + for (let a = 0; a < d; a++) mean[a]! /= m; + + const draw = normalDraws(0x5eed); + let basis = new Float64Array(k * d); + for (let i = 0; i < basis.length; i++) basis[i] = draw(); + orthonormalise(basis, k, d); + + const meanAlong = new Float64Array(k); + /** projected = (rows − mean) · basisᵀ */ + const project = (): void => { + for (let c = 0; c < k; c++) { + const co = c * d; + let sum = 0; + for (let a = 0; a < d; a++) sum += mean[a]! * basis[co + a]!; + meanAlong[c] = sum; + } + for (let i = 0; i < m; i++) { + const io = i * d; + for (let c = 0; c < k; c++) { + const co = c * d; + let sum = 0; + for (let a = 0; a < d; a++) sum += unit[io + a]! * basis[co + a]!; + projected[i * k + c] = sum - meanAlong[c]!; + } + } + }; + + for (let round = 0; round < rounds; round++) { + project(); + await breathe(); + // basis ← projectedᵀ · (rows − mean); the mean's share is zero, since + // every column of `projected` sums to zero. + const next = new Float64Array(k * d); + for (let i = 0; i < m; i++) { + const io = i * d; + for (let c = 0; c < k; c++) { + const weight = projected[i * k + c]!; + const co = c * d; + for (let a = 0; a < d; a++) next[co + a]! += weight * unit[io + a]!; + } + } + orthonormalise(next, k, d); + basis = next; + await breathe(); + } + project(); + return projected; +} + +/** What the model reads about every company: `rows` of `p` numbers, candidates first. */ +export interface LearnerFeatures { + features: Float64Array; + p: number; + candidates: number; + earlierGood: boolean[]; +} + +/** + * From embeddings to the model's features: each company on the main + * directions of this run's companies, then its relevance, then 1. The slow + * half of building a learner, and the half that does not depend on verdicts. + */ +export async function shortlistFeatures(args: { + vectors: ReadonlyArray; + relevance: readonly number[]; + earlier?: readonly EarlierVerdict[]; + settings?: Partial; +}): Promise { + const settings: LearnerSettings = { ...LEARNER_SETTINGS, ...args.settings }; + const n = args.vectors.length; + if (args.relevance.length !== n) + throw new Error("The learner needs one relevance per candidate"); + const d = args.vectors[0]?.length ?? 0; + const numbers = (vector: readonly number[]): boolean => vector.every(Number.isFinite); + // One number that is not a number would spread to every company's score: + // better no learner than one that can rank nobody. + for (let j = 0; j < n; j++) + if (!Number.isFinite(args.relevance[j]) || !numbers(args.vectors[j]!)) + throw new Error("A candidate's embedding or relevance is not a number"); + // An earlier verdict that cannot be compared is left out: embedded by + // another model (another size), or holding something that is not a number. + const earlier = (args.earlier ?? []).filter( + e => e.vector.length === d && Number.isFinite(e.relevance) && numbers(e.vector) + ); + const m = n + earlier.length; + + const unit = new Float32Array(m * d); + const fill = (row: number, vector: readonly number[]): void => { + if (vector.length !== d) throw new Error("Embeddings of different sizes cannot be ranked"); + let sq = 0; + for (let a = 0; a < d; a++) sq += vector[a]! * vector[a]!; + const scale = sq > 0 ? 1 / Math.sqrt(sq) : 0; + const o = row * d; + for (let a = 0; a < d; a++) unit[o + a] = vector[a]! * scale; + }; + for (let j = 0; j < n; j++) fill(j, args.vectors[j]!); + for (const [e, verdict] of earlier.entries()) fill(n + e, verdict.vector); + + const k = Math.max(0, Math.min(settings.dims, m - 1, d)); + const projected = await onMainDirections(unit, m, d, k, settings.rounds); + // Mean square length 1 over the candidates, so the prior spread means the + // same thing whatever the embedding model's scale. + let sumSq = 0; + for (let i = 0; i < n * k; i++) sumSq += projected[i]! * projected[i]!; + const scale = sumSq > 0 ? Math.sqrt(n / sumSq) : 1; + + const p = k + 2; + const features = new Float64Array(m * p); + for (let i = 0; i < m; i++) { + const o = i * p; + for (let c = 0; c < k; c++) features[o + c] = projected[i * k + c]! * scale; + features[o + k] = i < n ? args.relevance[i]! : earlier[i - n]!.relevance; + features[o + k + 1] = 1; + } + return { features, p, candidates: n, earlierGood: earlier.map(e => e.good) }; +} + +/** + * A learner over this run's candidates. `vectors` are their embeddings as the + * embedder returned them, `relevance` their relevance to the brief + * (./semantic's semanticRelevance); `earlier` are verdicts known before the + * run. Candidates keep their order: among equals, `next` prefers the earlier. + */ +export async function createShortlistLearner(args: { + vectors: ReadonlyArray; + relevance: readonly number[]; + earlier?: readonly EarlierVerdict[]; + settings?: Partial; +}): Promise { + return learnerOverFeatures({ ...(await shortlistFeatures(args)), settings: args.settings }); +} diff --git a/pipelines/src/distribution/run.test.ts b/pipelines/src/distribution/run.test.ts index 181d4f369..7182e5ccb 100644 --- a/pipelines/src/distribution/run.test.ts +++ b/pipelines/src/distribution/run.test.ts @@ -18,7 +18,17 @@ const store = vi.hoisted(() => ({ exclusions: { domains: [] as string[], keys: [] as string[] }, won: [] as string[], upserted: [] as ResolvedOrg[], + /** Rows of the shortlisted organisations, in the shortlist's order. */ + shortlist: [] as string[], wonCalls: 0, + /** What listFitExamples returns: verdicts known before the run. */ + examples: [] as Array<{ resolveKey: string; text: string; good: boolean; source: string }>, + /** Every saveFitVerdicts call. */ + saved: [] as Array<{ + basis: string; + segmentKey: string; + verdicts: Array<{ resolveKey: string; name: string; text: string; fit: boolean }>; + }>, })); vi.mock("@launchstack/tools/company-context", () => ({ @@ -49,15 +59,24 @@ vi.mock("./db", () => ({ }, findKnownOrgEntity: async () => null, updateOrg: async () => undefined, + listFitExamples: async () => store.examples, + saveFitVerdicts: async (args: (typeof store.saved)[number]) => { + store.saved.push(args); + }, upsertCandidateRelationships: async ({ items, }: { items: Array<{ orgId: string; kind: string }>; - }) => items.map((item, i) => ({ id: `rel-${i}`, ...item, stage: "lead" })), + }) => { + store.shortlist = items.map(item => item.orgId); + return items.map((item, i) => ({ id: `rel-${i}`, ...item, stage: "lead" })); + }, })); import { createFixturePorts } from "./fixture"; import { prepareRun, type DistributionPorts } from "./run"; +import { fakeEmbed } from "./semantic.fixture"; +import { LEARNING_ROUND, segmentKey } from "./shortlist"; const program = { id: "prog-1", @@ -177,7 +196,10 @@ beforeEach(() => { }; store.won = ["won.example"]; store.upserted = []; + store.shortlist = []; store.wonCalls = 0; + store.examples = []; + store.saved = []; }); describe("prepareRun discovery", () => { @@ -317,3 +339,266 @@ describe("prepareRun discovery", () => { expect(store.upserted.some(o => o.domain !== null && NEVER.includes(o.domain))).toBe(false); }); }); + +describe("prepareRun with a ranking that learns", () => { + // Two kinds of company the search returns. More of the brief's own words + // sit in the agencies' listings, so the fixed ranking puts every agency + // first; only the warehouse operators would buy picking robots. + const AGENCIES = 30; + const OPERATORS = 30; + const companies: CompanyHit[] = [ + ...Array.from({ length: AGENCIES }, (_, i) => ({ + ...hit(`agency-${i}.example`, `Agency ${i}`), + description: + "Picking robots and fulfilment warehouses: software consultancy and marketing agency for webshops.", + })), + ...Array.from({ length: OPERATORS }, (_, i) => ({ + ...hit(`operator-${i}.example`, `Operator ${i}`), + description: + "Fulfilment warehouses operator: picking, storage and shipping for webshops.", + })), + ]; + const isOperator = (name: string): boolean => name.startsWith("Operator"); + + function learningPorts(rounds: string[][], judge = true): DistributionPorts { + return { + ...livePorts({ described: [], searches: [] }), + searchCompanies: async query => + query.startsWith("Companies similar to") ? [] : companies, + embed: fakeEmbed, + judgeFit: judge + ? async ({ candidates }) => { + rounds.push(candidates.map(c => c.name)); + return new Map( + candidates.map(c => [ + c.id, + isOperator(c.name) + ? { fit: true, reason: "Runs a warehouse." } + : { fit: false, reason: "An agency." }, + ]) + ); + } + : null, + }; + } + + it("asks in small rounds, turns to the kind the verdicts favour, and keeps every verdict", async () => { + const rounds: string[][] = []; + const prepared = await prepareRun(ctx, learningPorts(rounds)); + + expect(rounds[0]).toHaveLength(LEARNING_ROUND); + const asked = rounds.flat(); + // The fixed ranking would ask all thirty agencies before the first operator. + expect(asked.filter(name => !isOperator(name)).length).toBeLessThan(AGENCIES / 2); + expect(prepared.candidateRelationshipIds).toHaveLength(25); + expect(prepared.fitCheck).toEqual({ + checked: asked.length, + rounds: rounds.length, + rejected: asked.filter(name => !isOperator(name)).length, + learning: true, + startedFrom: 0, + }); + + expect(store.saved).toHaveLength(1); + const saved = store.saved[0]!; + expect(saved.basis).toBe("listing"); + expect(saved.segmentKey).toBe(segmentKey(program)); + expect(saved.verdicts.map(v => v.name).sort()).toEqual([...asked].sort()); + expect(saved.verdicts.every(v => v.fit === isOperator(v.name))).toBe(true); + expect(saved.verdicts[0]!.text).toContain(saved.verdicts[0]!.name); + }); + + it("starts from the verdicts it is given and asks the right kind first", async () => { + // An earlier run met four companies of each kind; none of them comes back. + store.examples = [ + ...Array.from({ length: 4 }, (_, i) => ({ + resolveKey: `d:old-agency-${i}.example`, + text: `Old Agency ${i}. Picking robots and fulfilment warehouses: software consultancy and marketing agency for webshops.`, + good: false, + source: "listing", + })), + ...Array.from({ length: 4 }, (_, i) => ({ + resolveKey: `d:old-operator-${i}.example`, + text: `Old Operator ${i}. Fulfilment warehouses operator: picking, storage and shipping for webshops.`, + good: true, + // Two were won by a person, two judged a fit by an earlier run. + source: i < 2 ? "person" : "listing", + })), + ]; + const rounds: string[][] = []; + const prepared = await prepareRun(ctx, learningPorts(rounds)); + + expect(prepared.fitCheck?.startedFrom).toBe(8); + expect(rounds[0]!.filter(isOperator).length).toBeGreaterThanOrEqual(LEARNING_ROUND - 2); + // Nearly every check lands on a company that fits: about thirty for twenty-five places. + expect(prepared.fitCheck!.checked).toBeLessThanOrEqual(34); + }); + + it("without a fit check, orders the list by what earlier verdicts taught", async () => { + const before = await prepareRun(ctx, learningPorts([], false)); + expect(before.fitCheck).toBeUndefined(); + // By relevance alone: the agencies lead. + expect(store.upserted.slice(0, 10).every(o => !isOperator(o.name))).toBe(true); + + store.examples = [ + ...Array.from({ length: 4 }, (_, i) => ({ + resolveKey: `d:old-agency-${i}.example`, + text: `Old Agency ${i}. Picking robots and fulfilment warehouses: software consultancy and marketing agency for webshops.`, + good: false, + source: "person", + })), + ...Array.from({ length: 4 }, (_, i) => ({ + resolveKey: `d:old-operator-${i}.example`, + text: `Old Operator ${i}. Fulfilment warehouses operator: picking, storage and shipping for webshops.`, + good: true, + source: "person", + })), + ]; + await prepareRun(ctx, learningPorts([], false)); + expect(store.upserted.slice(0, 10).every(o => isOperator(o.name))).toBe(true); + expect(store.saved).toHaveLength(0); + }); + + it("keeps the fixed order and today's rounds when companies are matched by words", async () => { + const rounds: string[][] = []; + const prepared = await prepareRun(ctx, { ...learningPorts(rounds), embed: null }); + expect(rounds[0]).toHaveLength(50); + expect(prepared.fitCheck?.learning).toBe(false); + expect(prepared.fitCheck?.startedFrom).toBe(0); + }); + + /** The shortlist's company names, in its order. */ + const shortlisted = (): string[] => + store.shortlist.map(id => store.upserted[Number(id.replace("org-", ""))]!.name); + const COULD_NOT_FINISH = + "The fit check could not finish; part of the list is ranked by meaning only."; + const COULD_NOT_RUN = "The fit check could not run; nobody on the list was checked."; + const ONLY_THE_READ = + "The fit check could not finish; the list holds only the companies it read."; + + it("fills the places a broken-off fit check left open from the ranking", async () => { + const rounds: string[][] = []; + const ports = learningPorts(rounds); + let calls = 0; + const prepared = await prepareRun(ctx, { + ...ports, + judgeFit: async input => { + calls += 1; + if (calls === 2) throw new Error("model down"); + return ports.judgeFit!(input); + }, + }); + + // One round was read; the model failed on the second. + expect(rounds).toHaveLength(1); + const read = rounds[0]!; + const turnedAway = read.filter(name => !isOperator(name)); + expect(prepared.fitCheck).toEqual({ + checked: LEARNING_ROUND, + rounds: 1, + rejected: turnedAway.length, + learning: true, + startedFrom: 0, + incomplete: true, + }); + expect(prepared.warnings).toContain(COULD_NOT_FINISH); + + // The list is full all the same, and nobody the check turned away is on it. + const names = shortlisted(); + expect(names).toHaveLength(25); + expect(names.filter(name => turnedAway.includes(name))).toEqual([]); + // First the companies it read and kept, then the ranking's next ones, unread. + const kept = read.filter(isOperator); + expect(kept.length).toBeGreaterThan(0); + expect(names.slice(0, kept.length).sort()).toEqual([...kept].sort()); + const unread = store.upserted.map(o => o.name).filter(name => !read.includes(name)); + expect(names.slice(kept.length)).toEqual(unread.slice(0, 25 - kept.length)); + // What was read is still kept for the next run. + expect(store.saved[0]!.verdicts.map(v => v.name).sort()).toEqual([...read].sort()); + }); + + it("leaves the whole list to the ranking when the fit check fails at once", async () => { + const prepared = await prepareRun(ctx, { + ...learningPorts([]), + judgeFit: async () => { + throw new Error("model down"); + }, + }); + expect(prepared.fitCheck).toMatchObject({ checked: 0, rounds: 0, incomplete: true }); + expect(prepared.warnings).toContain(COULD_NOT_RUN); + expect(prepared.warnings).not.toContain(COULD_NOT_FINISH); + expect(shortlisted()).toEqual(store.upserted.slice(0, 25).map(o => o.name)); + }); + + it("says so when a broken-off fit check leaves only the companies it read", async () => { + // Every listing names Germany, outside this Dutch segment. The fit check + // reads such a company and may keep it; unread, it is out, as with no check. + const elsewhere: CompanyHit[] = Array.from({ length: 30 }, (_, i) => ({ + ...hit(`german-operator-${i}.example`, `German Operator ${i}`), + description: + "Fulfilment warehouses operator, with customers in Hamburg, Germany: picking, storage and shipping for webshops.", + })); + let calls = 0; + const prepared = await prepareRun(ctx, { + ...learningPorts([]), + searchCompanies: async query => + query.startsWith("Companies similar to") ? [] : elsewhere, + judgeFit: async ({ candidates }) => { + calls += 1; + if (calls === 2) throw new Error("model down"); + return new Map( + candidates.map(c => [c.id, { fit: true, reason: "Ships to the Netherlands." }]) + ); + }, + }); + expect(prepared.fitCheck).toMatchObject({ checked: LEARNING_ROUND, incomplete: true }); + // The ten it read and kept; the twenty it never reached stay out of the area. + expect(shortlisted()).toHaveLength(LEARNING_ROUND); + expect(prepared.warnings).toContain(ONLY_THE_READ); + expect(prepared.warnings).not.toContain(COULD_NOT_FINISH); + }); + + it("still checks every round when an earlier verdict's embedding is broken", async () => { + store.examples = [ + { + resolveKey: "d:broken.example", + text: "Broken Listing. Fulfilment warehouses operator.", + good: true, + source: "listing", + }, + ]; + const rounds: string[][] = []; + const prepared = await prepareRun(ctx, { + ...learningPorts(rounds), + embed: async texts => + (await fakeEmbed(texts)).map((vector, i) => + texts[i]!.startsWith("Broken") ? vector.map(() => Number.NaN) : vector + ), + }); + // The broken verdict is left out; the fit check runs as on a first run. + expect(prepared.fitCheck).toMatchObject({ learning: true, startedFrom: 0 }); + expect(prepared.fitCheck!.checked).toBeGreaterThanOrEqual(25); + expect(rounds[0]).toHaveLength(LEARNING_ROUND); + expect(shortlisted()).toHaveLength(25); + expect(shortlisted().every(isOperator)).toBe(true); + }); + + it("keeps verdicts under the question this run asked, not the segment's widest one", async () => { + const options = { + ...run.options, + territories: [{ country: "NL", region: "Utrecht" }], + partnerKinds: ["retailer" as const], + }; + store.program = { + ...program, + targetTerritories: [{ country: "NL" }, { country: "BE" }], + partnerKinds: ["distributor", "retailer"], + }; + store.run = { ...run, options }; + await prepareRun(ctx, learningPorts([])); + + const narrowed = segmentKey(store.program as ProgramRecord, options); + expect(store.saved[0]!.segmentKey).toBe(narrowed); + expect(narrowed).not.toBe(segmentKey(store.program as ProgramRecord)); + }); +}); diff --git a/pipelines/src/distribution/run.ts b/pipelines/src/distribution/run.ts index 7ccf46441..449f4e78e 100644 --- a/pipelines/src/distribution/run.ts +++ b/pipelines/src/distribution/run.ts @@ -39,6 +39,7 @@ import { type GatherPorts, type SearchCompaniesPort, } from "./gather"; +import { createShortlistLearner, type EarlierVerdict, type ShortlistLearner } from "./learn"; import { planDiscovery, type PlanInput, type SellerProfile } from "./plan"; import { makeDossierCreationKey, makeDossierFilename, renderDossierMarkdown } from "./render"; import { bestTerritoryFit, placeLabel } from "./locate"; @@ -50,9 +51,12 @@ import { relevanceShare, type EmbedTexts, type JudgeFit, + type Relevance, } from "./semantic"; +import { fillShortlist, segmentKey } from "./shortlist"; import type { DiscoveryPlan, + FitCheckSummary, PartnerKind, ProgramRecord, RelationshipRecord, @@ -155,9 +159,6 @@ export interface DistributionPorts { judgeFit?: JudgeFit | null; } -/** Companies the model checks per open shortlist place, each round down the ranking. */ -const JUDGE_POOL_FACTOR = 2; - export interface RunContext { runId: string; companyId: bigint; @@ -201,6 +202,72 @@ export interface PrepareRunResult { excluded: number; warnings: string[]; profile: SellerProfile; + /** What the fit check of the shortlist came to; absent when there was none. */ + fitCheck?: FitCheckSummary; +} + +/** + * A ranking that learns, over the queue's companies in its order: from the + * fit check's verdicts as they arrive, and before that from what is already + * known about the segment (./db's listFitExamples). Null when companies were + * matched by shared words, and when nothing could be learned: no fit check to + * come and no earlier verdict. A failure here never stops a run: earlier + * verdicts that cannot be read are done without, and when the learner cannot + * be built the fixed ranking takes over. + */ +async function startLearner(args: { + ctx: RunContext; + relevance: Relevance; + queue: readonly ResolvedOrg[]; + scoreOf: ReadonlyMap; + vectorOf: ReadonlyMap; + /** ./shortlist's segmentKey of what this run asks the fit check. */ + verdictKey: string; + /** A fit check follows: explore what is still unknown. Without one, rank by what is known. */ + fitCheck: boolean; +}): Promise { + const { ctx, relevance, queue } = args; + if (relevance.method !== "semantic" || queue.length === 0) return null; + const vectors: number[][] = []; + for (const org of queue) { + const vector = args.vectorOf.get(org.resolveKey); + if (!vector || vector.length === 0) return null; + vectors.push(vector); + } + let earlier: EarlierVerdict[] = []; + try { + const examples = await db.listFitExamples({ + companyId: ctx.companyId, + programId: ctx.programId, + segmentKey: args.verdictKey, + }); + if (examples.length > 0 && relevance.measure) { + const measured = await relevance.measure(examples.map(e => e.text)); + earlier = examples.flatMap((example, i) => { + const vector = measured.vectors[i]; + return vector + ? [{ vector, relevance: measured.scores[i] ?? 0, good: example.good }] + : []; + }); + } + } catch (error) { + console.warn( + `${LOG_PREFIX} earlier verdicts unavailable; the ranking starts fresh:`, + error + ); + } + if (!args.fitCheck && earlier.length === 0) return null; + try { + return await createShortlistLearner({ + vectors, + relevance: queue.map(org => args.scoreOf.get(org.resolveKey) ?? 0), + earlier, + settings: args.fitCheck ? undefined : { bonus: 0 }, + }); + } catch (error) { + console.warn(`${LOG_PREFIX} the ranking could not learn; keeping the fixed order:`, error); + return null; + } } function pickKind(org: ResolvedOrg, wanted: PartnerKind[]): PartnerKind { @@ -395,6 +462,7 @@ export async function prepareRun( const relevance = await relevanceOf(ports.embed, program, partnerKinds, orgs, profile); const scoreOf = new Map(orgs.map((o, i) => [o.resolveKey, relevance.scores[i] ?? 0])); + const vectorOf = new Map(orgs.map((o, i) => [o.resolveKey, relevance.vectors?.[i]])); if (relevance.method === "lexical") warnings.push( "No embedding model is configured, so companies were matched by shared words rather than by meaning." @@ -407,12 +475,14 @@ export async function prepareRun( // the text states, a real domain, and mentions. const wanted = new Set(partnerKinds); const FIT_RANK = { in: 2, unknown: 1, out: 0 }; + // Relevance, until earlier verdicts say more (no fit check to ask). + let rankScoreOf: ReadonlyMap = scoreOf; const byRank = (a: ResolvedOrg, b: ResolvedOrg) => { const fitA = FIT_RANK[fitOf.get(a.resolveKey) ?? "unknown"]; const fitB = FIT_RANK[fitOf.get(b.resolveKey) ?? "unknown"]; if (fitA !== fitB) return fitB - fitA; - const relA = scoreOf.get(a.resolveKey) ?? 0; - const relB = scoreOf.get(b.resolveKey) ?? 0; + const relA = rankScoreOf.get(a.resolveKey) ?? 0; + const relB = rankScoreOf.get(b.resolveKey) ?? 0; if (relA !== relB) return relB - relA; const roleA = a.roles.some(r => wanted.has(r)) ? 1 : 0; const roleB = b.roles.some(r => wanted.has(r)) ? 1 : 0; @@ -424,48 +494,99 @@ export async function prepareRun( }; let notBuyers = 0; - // Companies the fit check saw; the shortlist comes from these alone. + // Companies the fit check saw; the shortlist comes from these alone, + // unless the check broke off: then the places it left open go to + // the next companies down the ranking, unchecked (those named + // outside the area stay out, as they do with no fit check at all). let checked: Set | null = null; - if (ports.judgeFit && orgs.length > 0) { - const queue = [...orgs].sort(byRank); - const seen = new Set(); + let brokeOff = false; + let fitCheck: FitCheckSummary | undefined; + // What this run asks the fit check: kept verdicts answer this and no other question. + const verdictKey = segmentKey(program, options); + // The fixed ranking, and over it a ranking that learns: from the + // fit check's verdicts round by round, and from what earlier runs + // and people's own decisions already said about this segment. + const queue = [...orgs].sort(byRank); + const learner = await startLearner({ + ctx, + relevance, + queue, + scoreOf, + vectorOf, + verdictKey, + fitCheck: Boolean(ports.judgeFit), + }); + const startedFrom = learner?.learnedFrom ?? 0; + if (ports.judgeFit && queue.length > 0) { + const judgeFit = ports.judgeFit; + const brief = buyerBrief(program, partnerKinds, profile); + const where = territories.map(placeLabel).join("; "); + const textOf = new Map(queue.map(o => [o.resolveKey, companyText(o)])); + // Down the ranking until the shortlist is full or no one is left. + const outcome = await fillShortlist({ + queue: queue.map(o => ({ + id: o.resolveKey, + name: o.name, + text: textOf.get(o.resolveKey)!, + })), + wanted: options.maxCandidates, + judge: batch => judgeFit({ brief, where, seller: profile, candidates: batch }), + learner, + tierOf: index => FIT_RANK[fitOf.get(queue[index]!.resolveKey) ?? "unknown"], + }); + if (outcome.error) { + brokeOff = true; + console.warn( + `${LOG_PREFIX} fit check failed; keeping the ranking:`, + outcome.error + ); + } + if (outcome.learnerQuit) + console.warn( + `${LOG_PREFIX} the ranking could not go on learning; the fixed order took over` + ); + const seen = new Set(outcome.checked); const rejected = new Set(); - // Down the ranking until the shortlist is full or no one is - // left: a batch of no's must not end the run with an empty list. - let at = 0; - let kept = 0; + for (const o of queue) { + const verdict = outcome.verdicts.get(o.resolveKey); + if (!verdict || verdict.fit) continue; + rejected.add(o.resolveKey); + console.info(`${LOG_PREFIX} fit check left out ${o.name}: ${verdict.reason}`); + } + // Kept for the next run's ranking to start from. try { - while (at < queue.length && kept < options.maxCandidates) { - const room = options.maxCandidates - kept; - const batch = queue.slice(at, at + room * JUDGE_POOL_FACTOR); - at += batch.length; - const verdicts = await ports.judgeFit({ - brief: buyerBrief(program, partnerKinds, profile), - where: territories.map(placeLabel).join("; "), - seller: profile, - candidates: batch.map(o => ({ - id: o.resolveKey, - name: o.name, - text: companyText(o), - })), - }); - for (const o of batch) { - seen.add(o.resolveKey); - const verdict = verdicts.get(o.resolveKey); - if (verdict && !verdict.fit) { - rejected.add(o.resolveKey); - console.info( - `${LOG_PREFIX} fit check left out ${o.name}: ${verdict.reason}` - ); - } else kept += 1; - } - } + await db.saveFitVerdicts({ + companyId: ctx.companyId, + programId: ctx.programId, + runId: ctx.runId, + basis: "listing", + segmentKey: verdictKey, + verdicts: queue.flatMap(o => { + const verdict = outcome.verdicts.get(o.resolveKey); + return verdict + ? [ + { + resolveKey: o.resolveKey, + name: o.name, + text: textOf.get(o.resolveKey)!, + fit: verdict.fit, + reason: verdict.reason, + }, + ] + : []; + }), + }); } catch (error) { - console.warn(`${LOG_PREFIX} fit check failed; keeping the ranking:`, error); - warnings.push( - "The fit check could not finish; part of the list is ranked by meaning only." - ); + console.warn(`${LOG_PREFIX} could not keep the fit check's verdicts:`, error); } + fitCheck = { + checked: outcome.checked.length, + rounds: outcome.rounds, + rejected: rejected.size, + learning: learner !== null && !outcome.learnerQuit, + startedFrom, + ...(brokeOff ? { incomplete: true } : {}), + }; notBuyers = rejected.size; orgs = orgs.filter(o => !rejected.has(o.resolveKey)); if (seen.size > 0) checked = seen; @@ -475,6 +596,10 @@ export async function prepareRun( orgs = orgs .filter(o => !isOut(o) || seen.has(o.resolveKey)) .map(o => (isOut(o) ? { ...o, country: null, region: null, city: null } : o)); + } else if (learner) { + // No fit check to ask: order by what earlier verdicts taught. + const predicted = learner.predicted(); + rankScoreOf = new Map(queue.map((o, i) => [o.resolveKey, predicted[i] ?? 0])); } if (outOfArea + offTopic + notBuyers > 0) warnings.push( @@ -482,9 +607,26 @@ export async function prepareRun( ); const ranked = [...orgs].sort(byRank); - const shortlist = ranked - .filter(o => !checked || checked.has(o.resolveKey)) - .slice(0, options.maxCandidates); + const read = checked; + const shortlist = ( + read && brokeOff + ? [ + ...ranked.filter(o => read.has(o.resolveKey)), + ...ranked.filter(o => !read.has(o.resolveKey)), + ] + : ranked.filter(o => !read || read.has(o.resolveKey)) + ).slice(0, options.maxCandidates); + // Say what the list is after a check that broke off. A company named + // outside the area that the check never read is out all the same, so + // the list can be short of its places, and then nobody on it is unread. + if (brokeOff) + warnings.push( + !read + ? "The fit check could not run; nobody on the list was checked." + : shortlist.some(o => !read.has(o.resolveKey)) + ? "The fit check could not finish; part of the list is ranked by meaning only." + : "The fit check could not finish; the list holds only the companies it read." + ); const saved = await db.upsertOrgs({ companyId: ctx.companyId, runId: ctx.runId, @@ -535,10 +677,16 @@ export async function prepareRun( items.findIndex(i => i.orgId === b.orgId) ) .map(r => r.id); - return { resolved: orgs.length, excluded, candidateIds, mentions: mentions.length }; + return { + resolved: orgs.length, + excluded, + candidateIds, + mentions: mentions.length, + fitCheck, + }; }, report: value => ({ - detail: `${value.resolved} organisations, ${value.excluded} excluded, ${value.candidateIds.length} shortlisted`, + detail: `${value.resolved} organisations, ${value.excluded} excluded, ${value.candidateIds.length} shortlisted${value.fitCheck ? `, ${value.fitCheck.checked} checked for fit in ${value.fitCheck.rounds} round${value.fitCheck.rounds === 1 ? "" : "s"}` : ""}`, }), }); @@ -554,6 +702,7 @@ export async function prepareRun( excluded: resolvedResult.excluded, warnings, profile, + ...(resolvedResult.fitCheck ? { fitCheck: resolvedResult.fitCheck } : {}), }; } @@ -721,6 +870,40 @@ export async function enrichCandidate( rejectedBecause = verdict.reason; console.info(`${LOG_PREFIX} research ruled out ${org.name}: ${verdict.reason}`); } + // What research found outranks the look at the listing: the next + // run's ranking learns from it, under the listing's own words and + // the key this run's listing verdicts are kept under. + if (verdict) + await db + .getRun(ctx.runId, ctx.companyId) + .then(run => + db.saveFitVerdicts({ + companyId: ctx.companyId, + programId: ctx.programId, + runId: ctx.runId, + basis: "research", + segmentKey: segmentKey(program, run?.options), + verdicts: [ + { + resolveKey: org.resolveKey, + name: org.name, + text: companyText({ + name: org.name, + categories: org.categories, + description: org.description, + }), + fit: verdict.fit, + reason: verdict.reason, + }, + ], + }) + ) + .catch((error: unknown) => + console.warn( + `${LOG_PREFIX} could not keep the verdict on ${org.name}:`, + error + ) + ); } catch (error) { console.warn(`${LOG_PREFIX} fit check after research failed for ${org.name}:`, error); } @@ -869,7 +1052,8 @@ export async function finalizeRun( prepared: Pick< PrepareRunResult, "sources" | "mentions" | "resolved" | "excluded" | "warnings" | "candidateRelationshipIds" - >, + > & + Pick, "fitCheck">, enriched: EnrichCandidateResult[], startedAt: Date ): Promise { @@ -899,6 +1083,7 @@ export async function finalizeRun( warnings: prepared.warnings, tokens, wallMs: Date.now() - startedAt.getTime(), + ...(prepared.fitCheck ? { fitCheck: prepared.fitCheck } : {}), }; await db.updateRun(ctx.runId, ctx.companyId, { status: "completed", diff --git a/pipelines/src/distribution/schema.ts b/pipelines/src/distribution/schema.ts index 8ff43e579..807109473 100644 --- a/pipelines/src/distribution/schema.ts +++ b/pipelines/src/distribution/schema.ts @@ -1,7 +1,7 @@ /** * Drizzle schema for the distribution pipeline (design §4.3). * - * Nine product tables, all company-scoped with cascade delete, prefixed + * Ten product tables, all company-scoped with cascade delete, prefixed * `pdr_ai_v2_` by the shared helper. Columns added by later migrations must * be declared LAST (the pg_dump parity gate compares column order). */ @@ -10,6 +10,7 @@ import type { InferSelectModel } from "drizzle-orm"; import { bigint, bigserial, + boolean, date, doublePrecision, index, @@ -379,3 +380,61 @@ export const marketEdges = pgTable( }) ); export type MarketEdgeRow = InferSelectModel; + +// ─── Fit verdicts ──────────────────────────────────────────────────────────── + +/** + * What the fit check said about a company for a segment: one row per + * organisation and program, holding the latest verdict. Kept so the next + * run's ranking starts from what earlier runs learned (./learn) instead of + * from nothing. People's own decisions need no row here: they are the stage + * of the deal (won, lost). + * + * A company the fit check turned away never gets a partner_orgs row, so the + * verdict carries the company's own words as the ranking read them. + */ +export const distributionFitVerdicts = pgTable( + "distribution_fit_verdicts", + { + id: bigserial("id", { mode: "number" }).primaryKey(), + companyId: bigint("company_id", { mode: "bigint" }) + .notNull() + .references(() => company.id, { onDelete: "cascade" }), + programId: varchar("program_id", { length: 256 }) + .notNull() + .references(() => distributionPrograms.id, { onDelete: "cascade" }), + /** From @launchstack/tools/org-resolver, as partner_orgs.resolve_key. */ + resolveKey: varchar("resolve_key", { length: 512 }).notNull(), + name: varchar("name", { length: 512 }).notNull(), + /** The company's listing in its own words (./semantic's companyText): what a ranking reads. */ + text: text("text").notNull(), + fit: boolean("fit").notNull(), + reason: text("reason"), + /** `listing`: judged on its listing, before research. `research`: judged on what research found. */ + basis: varchar("basis", { length: 16, enum: ["listing", "research"] }).notNull(), + /** + * Hash of the question the fit check was asked (./shortlist's + * segmentKey): a rewritten or moved segment starts afresh. + */ + segmentKey: varchar("segment_key", { length: 64 }).notNull(), + runId: varchar("run_id", { length: 256 }).references(() => distributionRuns.id, { + onDelete: "set null", + }), + judgedAt: timestamp("judged_at", { withTimezone: true }) + .default(sql`CURRENT_TIMESTAMP`) + .notNull(), + }, + table => ({ + programOrgUnique: uniqueIndex("distribution_fit_verdicts_program_org_unique").on( + table.companyId, + table.programId, + table.resolveKey + ), + companyIdx: index("distribution_fit_verdicts_company_idx").on(table.companyId), + programIdx: index("distribution_fit_verdicts_program_idx").on( + table.programId, + table.judgedAt + ), + }) +); +export type DistributionFitVerdictRow = InferSelectModel; diff --git a/pipelines/src/distribution/semantic.test.ts b/pipelines/src/distribution/semantic.test.ts index a59ccf09f..7687daf61 100644 --- a/pipelines/src/distribution/semantic.test.ts +++ b/pipelines/src/distribution/semantic.test.ts @@ -87,6 +87,20 @@ describe("relevance by meaning", () => { expect(semantic.method).toBe("semantic"); }); + it("hands back each company's embedding, and measures more texts against the same brief", async () => { + const companies = [{ name: "Specialty coffee importer" }, { name: "Mango" }]; + const semantic = await relevanceOf(fakeEmbed, program, ["retailer"], companies); + expect(semantic.vectors).toEqual(await fakeEmbed(companies.map(c => c.name))); + // A verdict an earlier run kept, on a company that is not a candidate now. + const more = await semantic.measure!(["Specialty coffee importer", "Tea room"]); + expect(more.scores[0]).toBe(semantic.scores[0]); + expect(more.vectors).toHaveLength(2); + // Matched by words there is nothing to hand back, and nothing learns. + const lexical = await relevanceOf(null, program, ["retailer"], companies); + expect(lexical.vectors).toBeUndefined(); + expect(lexical.measure).toBeUndefined(); + }); + it("turns relevance into a share of the rubric's topic points", () => { expect(relevanceShare(-0.2, "semantic")).toBe(0); expect(relevanceShare(0.2, "semantic")).toBeCloseTo(0.5); diff --git a/pipelines/src/distribution/semantic.ts b/pipelines/src/distribution/semantic.ts index 9ed318873..f4f871eef 100644 --- a/pipelines/src/distribution/semantic.ts +++ b/pipelines/src/distribution/semantic.ts @@ -104,28 +104,44 @@ export function cosine(a: readonly number[], b: readonly number[]): number { const BATCH = 64; +/** A brief, embedded once: what each company's text is measured against. */ +export interface RelevanceMeter { + /** Relevance of each text to the brief, and each text's embedding, in the order given. */ + measure(texts: readonly string[]): Promise<{ scores: number[]; vectors: number[][] }>; +} + /** - * Relevance of each text to the brief, in (-∞, 1]: (sim(text, brief) − - * sim(text, baseline)) / (1 − sim(brief, baseline)). Above zero is relevant. + * Relevance in (-∞, 1]: (sim(text, brief) − sim(text, baseline)) / (1 − + * sim(brief, baseline)). Above zero is relevant. */ +export async function relevanceMeter(embed: EmbedTexts, brief: string): Promise { + const [briefVector, baselineVector] = await embed([brief, BASELINE_TEXT]); + if (!briefVector || !baselineVector) throw new Error("The embedder returned no vectors"); + const span = 1 - cosine(briefVector, baselineVector); + return { + async measure(texts) { + const scores: number[] = []; + const vectors: number[][] = []; + for (let i = 0; i < texts.length; i += BATCH) { + for (const v of await embed(texts.slice(i, i + BATCH))) { + const toBrief = cosine(v, briefVector); + const toBaseline = cosine(v, baselineVector); + scores.push(span > 0 ? (toBrief - toBaseline) / span : toBrief - toBaseline); + vectors.push(v); + } + } + return { scores, vectors }; + }, + }; +} + +/** Relevance of each text to the brief (see relevanceMeter). */ export async function semanticRelevance( embed: EmbedTexts, brief: string, texts: readonly string[] ): Promise { - const [briefVector, baselineVector] = await embed([brief, BASELINE_TEXT]); - if (!briefVector || !baselineVector) throw new Error("The embedder returned no vectors"); - const span = 1 - cosine(briefVector, baselineVector); - const out: number[] = []; - for (let i = 0; i < texts.length; i += BATCH) { - const vectors = await embed(texts.slice(i, i + BATCH)); - for (const v of vectors) { - const toBrief = cosine(v, briefVector); - const toBaseline = cosine(v, baselineVector); - out.push(span > 0 ? (toBrief - toBaseline) / span : toBrief - toBaseline); - } - } - return out; + return (await (await relevanceMeter(embed, brief)).measure(texts)).scores; } /** Word-overlap relevance in [0, 1]: the fallback when no embedder is configured. */ @@ -140,6 +156,10 @@ export interface Relevance { /** By meaning (embeddings) or by shared words (no embedder configured). */ method: "semantic" | "lexical"; scores: number[]; + /** By meaning only: each company's embedding, in the order given. A ranking that learns reads them (./learn). */ + vectors?: number[][]; + /** By meaning only: more texts against the same brief (verdicts an earlier run kept). */ + measure?: RelevanceMeter["measure"]; } /** @@ -155,12 +175,14 @@ export async function relevanceOf( ): Promise { if (embed && companies.length > 0) { try { - const scores = await semanticRelevance( - embed, - buyerBrief(program, partnerKinds, seller), - companies.map(companyText) - ); - return { method: "semantic", scores }; + const meter = await relevanceMeter(embed, buyerBrief(program, partnerKinds, seller)); + const { scores, vectors } = await meter.measure(companies.map(companyText)); + return { + method: "semantic", + scores, + vectors, + measure: texts => meter.measure(texts), + }; } catch (error) { console.warn("[distribution] embeddings failed; matching by words instead:", error); } diff --git a/pipelines/src/distribution/shortlist.test.ts b/pipelines/src/distribution/shortlist.test.ts new file mode 100644 index 000000000..5e9b13ee3 --- /dev/null +++ b/pipelines/src/distribution/shortlist.test.ts @@ -0,0 +1,262 @@ +import { describe, expect, it } from "vitest"; + +import { createShortlistLearner } from "./learn"; +import type { FitVerdict } from "./semantic"; +import { fillShortlist, LEARNING_ROUND, segmentKey, type ShortlistCandidate } from "./shortlist"; +import type { PartnerKind } from "./types"; + +const candidates = (count: number): ShortlistCandidate[] => + Array.from({ length: count }, (_, i) => ({ id: `c${i}`, name: `Company ${i}`, text: `c${i}` })); + +/** A judge that answers from a rule and remembers what each round asked. */ +function judgeBy(fit: (id: string) => boolean | undefined) { + const rounds: string[][] = []; + const judge = async (batch: ShortlistCandidate[]): Promise> => { + rounds.push(batch.map(c => c.id)); + const out = new Map(); + for (const c of batch) { + const verdict = fit(c.id); + if (verdict !== undefined) out.set(c.id, { fit: verdict, reason: verdict ? "" : "no" }); + } + return out; + }; + return { judge, rounds }; +} + +describe("segmentKey", () => { + const segment = { + offering: "Picking robots for fulfilment warehouses", + categories: ["fulfilment", "3PL"], + constraints: null, + partnerKinds: ["distributor", "retailer"] as PartnerKind[], + targetTerritories: [{ country: "NL" }, { country: "BE", region: "Flanders" }], + }; + + it("is the same for the same question, however it is written down", () => { + expect(segmentKey(segment)).toBe( + segmentKey({ ...segment, offering: ` ${segment.offering}\n`, constraints: "" }) + ); + // Lists are sets: another order, or an entry given twice, asks the same thing. + expect(segmentKey(segment)).toBe( + segmentKey({ + ...segment, + categories: ["3PL", "fulfilment", "3PL"], + partnerKinds: ["retailer", "distributor", "retailer"], + targetTerritories: [ + { country: "BE", region: "Flanders" }, + { country: "NL" }, + { country: "NL" }, + ], + }) + ); + expect(segmentKey(segment)).toMatch(/^[0-9a-f]{32}$/); + }); + + it("changes when what is sold, who buys it, what rules a company out or where changes", () => { + const keys = new Set([ + segmentKey(segment), + segmentKey({ ...segment, offering: "Shelving for fulfilment warehouses" }), + segmentKey({ ...segment, categories: ["fulfilment"] }), + segmentKey({ ...segment, constraints: "No companies under ten people" }), + segmentKey({ ...segment, partnerKinds: ["distributor"] }), + segmentKey({ ...segment, targetTerritories: [{ country: "BE" }] }), + segmentKey({ ...segment, targetTerritories: [{ country: "NL" }, { country: "BE" }] }), + ]); + expect(keys.size).toBe(7); + }); + + it("is the run's own question when a run narrows the segment", () => { + const narrowed = segmentKey(segment, { + territories: [{ country: "NL" }], + partnerKinds: ["distributor"], + }); + expect(narrowed).not.toBe(segmentKey(segment)); + expect(narrowed).toBe( + segmentKey({ + ...segment, + targetTerritories: [{ country: "NL" }], + partnerKinds: ["distributor"], + }) + ); + // Options that narrow nothing leave the segment's own key. + expect(segmentKey(segment, { territories: [], partnerKinds: undefined })).toBe( + segmentKey(segment) + ); + expect(segmentKey(segment, null)).toBe(segmentKey(segment)); + }); +}); + +describe("fillShortlist with the fixed ranking", () => { + it("checks twice the open places per round, down the list, until the list is full", async () => { + const { judge, rounds } = judgeBy(id => Number(id.slice(1)) % 2 === 0); + const result = await fillShortlist({ queue: candidates(40), wanted: 5, judge }); + // Round 1: ten companies, five fit. The list is full. + expect(rounds).toEqual([Array.from({ length: 10 }, (_, i) => `c${i}`)]); + expect(result.kept).toBe(5); + expect(result.rounds).toBe(1); + expect(result.checked).toHaveLength(10); + }); + + it("goes on down the ranking after a round of no's", async () => { + const { judge, rounds } = judgeBy(id => Number(id.slice(1)) >= 6); + const result = await fillShortlist({ queue: candidates(12), wanted: 3, judge }); + expect(rounds.map(r => r.length)).toEqual([6, 6]); + expect(result.kept).toBe(6); + expect([...result.verdicts.values()].filter(v => !v.fit)).toHaveLength(6); + }); + + it("ends when nobody is left", async () => { + const { judge } = judgeBy(() => false); + const result = await fillShortlist({ queue: candidates(7), wanted: 5, judge }); + expect(result.checked).toHaveLength(7); + expect(result.kept).toBe(0); + }); + + it("keeps a company the judge did not answer for", async () => { + const { judge } = judgeBy(id => (id === "c1" ? undefined : false)); + const result = await fillShortlist({ queue: candidates(4), wanted: 2, judge }); + expect(result.kept).toBe(1); + expect(result.verdicts.has("c1")).toBe(false); + expect(result.checked).toContain("c1"); + }); + + it("keeps what it saw when a round fails", async () => { + let calls = 0; + const result = await fillShortlist({ + queue: candidates(20), + wanted: 4, + judge: async batch => { + calls += 1; + if (calls === 2) throw new Error("model down"); + return new Map(batch.map(c => [c.id, { fit: false, reason: "no" }])); + }, + }); + expect(result.error).toBeInstanceOf(Error); + expect(result.checked).toHaveLength(8); + expect(result.rounds).toBe(1); + }); +}); + +describe("fillShortlist with a learner", () => { + /** Forty companies of two kinds; only the second kind fits, and relevance favours the first. */ + function pool() { + const vectors: number[][] = []; + const relevance: number[] = []; + for (let i = 0; i < 40; i++) { + const second = i >= 20; + const v = Array.from({ length: 8 }, (_, a) => Math.sin(i * 7 + a * 3) * 0.2); + v[second ? 1 : 0]! += 1; + vectors.push(v); + relevance.push(second ? 0.2 - (i - 20) * 0.001 : 0.3 - i * 0.001); + } + return { vectors, relevance, queue: candidates(40) }; + } + const fits = (id: string): boolean => Number(id.slice(1)) >= 20; + + it("asks in small rounds and turns to the kind the verdicts favour", async () => { + const { vectors, relevance, queue } = pool(); + const fixed = judgeBy(fits); + const before = await fillShortlist({ + queue, + wanted: 10, + judge: fixed.judge, + maxChecks: 30, + }); + const learner = await createShortlistLearner({ vectors, relevance }); + const learning = judgeBy(fits); + const after = await fillShortlist({ + queue, + wanted: 10, + judge: learning.judge, + learner, + maxChecks: 30, + }); + expect(learning.rounds[0]).toHaveLength(LEARNING_ROUND); + // The fixed ranking spends its first twenty checks on the kind that never fits. + expect(before.kept).toBeLessThan(after.kept); + // A round may overshoot the open places, as with the fixed ranking. + expect(after.kept).toBeGreaterThanOrEqual(10); + expect(after.checked.length).toBeLessThan(30); + expect(learner.learnedFrom).toBe(after.checked.length); + }); + + it("shrinks the last rounds to twice the open places", async () => { + const { vectors, relevance, queue } = pool(); + const learner = await createShortlistLearner({ vectors, relevance }); + const { judge, rounds } = judgeBy(() => true); + await fillShortlist({ queue, wanted: 12, judge, learner }); + // Ten fit, then two places are open: four are asked, not ten. + expect(rounds.map(r => r.length)).toEqual([10, 4]); + }); + + it("works through a higher area tier before touching a lower one", async () => { + const { vectors, relevance, queue } = pool(); + const learner = await createShortlistLearner({ vectors, relevance }); + const { judge, rounds } = judgeBy(fits); + // The first kind is confirmed in the area, the second is not. + await fillShortlist({ + queue, + wanted: 5, + judge, + learner, + tierOf: index => (index < 20 ? 2 : 1), + }); + const asked = rounds.flat().map(id => Number(id.slice(1))); + const firstLow = asked.findIndex(i => i >= 20); + expect(firstLow).toBe(20); + expect(asked.slice(0, 20).every(i => i < 20)).toBe(true); + }); + + it("does not learn from a company the judge did not answer for", async () => { + const { vectors, relevance, queue } = pool(); + const learner = await createShortlistLearner({ vectors, relevance }); + // Whoever is asked about first gets no answer. + let unanswered: string | null = null; + const { judge } = judgeBy(id => { + unanswered ??= id; + return id === unanswered ? undefined : fits(id); + }); + const result = await fillShortlist({ queue, wanted: 3, judge, learner, maxChecks: 10 }); + expect(result.checked[0]).toBe(unanswered); + expect(result.verdicts.has(unanswered!)).toBe(false); + expect(learner.learnedFrom).toBe(result.checked.length - 1); + }); + + it("goes on down the fixed order when the learner has nobody to offer", async () => { + const { vectors, relevance, queue } = pool(); + const real = await createShortlistLearner({ vectors, relevance }); + // A learner that ranks one round and then loses its footing. + let calls = 0; + const learner = { + next: (count: number, among?: (index: number) => boolean) => + calls++ === 0 ? real.next(count, among) : [], + observe: real.observe.bind(real), + skip: real.skip.bind(real), + }; + const { judge, rounds } = judgeBy(fits); + const result = await fillShortlist({ queue, wanted: 10, judge, learner }); + + expect(result.learnerQuit).toBe(true); + expect(result.error).toBeUndefined(); + expect(result.kept).toBeGreaterThanOrEqual(10); + // Nobody is asked about twice, and after the first round the order is the queue's. + const asked = rounds.flat(); + expect(new Set(asked).size).toBe(asked.length); + const later = rounds + .slice(1) + .flat() + .map(id => Number(id.slice(1))); + expect(later).toEqual([...later].sort((a, b) => a - b)); + const first = new Set(rounds[0]); + expect(later[0]).toBe(queue.findIndex(c => !first.has(c.id))); + }); + + it("does not report a learner that simply ran out of companies", async () => { + const { vectors, relevance, queue } = pool(); + const learner = await createShortlistLearner({ vectors, relevance }); + const { judge } = judgeBy(() => false); + const result = await fillShortlist({ queue, wanted: 5, judge, learner }); + expect(result.checked).toHaveLength(queue.length); + expect(result.learnerQuit).toBeUndefined(); + }); +}); diff --git a/pipelines/src/distribution/shortlist.ts b/pipelines/src/distribution/shortlist.ts new file mode 100644 index 000000000..88b6a9e9b --- /dev/null +++ b/pipelines/src/distribution/shortlist.ts @@ -0,0 +1,188 @@ +/** + * The fit check of a run's candidates, round by round: who is asked "would + * this business buy this?", in which order, until the shortlist is full. + * + * With the fixed ranking a round checks the next companies down the list, + * twice as many as there are open places. With a learner (./learn) a round is + * small and the learner picks it: after each round it re-ranks everyone not + * checked yet from the verdicts so far, and the highest ranked go next. + * + * The model call is the `judge` port, so a run, a test and the experiment's + * replay all go through this same loop. + */ +import { createHash } from "node:crypto"; + +import type { ShortlistLearner } from "./learn"; +import { placeLabel } from "./locate"; +import type { FitVerdict } from "./semantic"; +import type { PartnerKind, ProgramRecord, Territory } from "./types"; + +export interface ShortlistCandidate { + id: string; + name: string; + /** The company's own words, as the fit check reads them. */ + text: string; +} + +/** Companies the fixed ranking checks per open shortlist place, each round down the list. */ +export const JUDGE_POOL_FACTOR = 2; + +/** + * Companies checked per round when the ranking learns. One model call, and + * small enough that a round's verdicts steer the next one. The experiment (E4, + * batch-size runs) found 79.5 good companies in 100 checks with 5 per round + * and 78.7 with 10, so the larger one is used and a run makes half the calls. + */ +export const LEARNING_ROUND = 10; + +/** A list as the set it stands for: no repeats, in one order. */ +const asSet = (items: readonly string[]): string[] => [...new Set(items)].sort(); + +/** + * The question a run puts to the fit check about a segment: what the segment + * sells, who buys it and as what, what rules a company out, and where. The + * fit check's verdicts are kept under this key, so a rewritten segment, a + * moved area or a run over one part of the segment starts afresh instead of + * learning from answers to a different question. Lists count as sets: + * reordering or repeating an entry asks the same thing. The seller's own profile is left out; + * it is the same seller whatever its documents say this month. + */ +export function segmentKey( + program: Pick< + ProgramRecord, + "offering" | "categories" | "constraints" | "partnerKinds" | "targetTerritories" + >, + /** The run's own narrowing of the segment (its options), when it has one. */ + run?: { + partnerKinds?: readonly PartnerKind[]; + territories?: readonly Territory[]; + } | null +): string { + const kinds = run?.partnerKinds?.length ? run.partnerKinds : program.partnerKinds; + const territories = run?.territories?.length ? run.territories : program.targetTerritories; + return createHash("sha256") + .update( + JSON.stringify([ + program.offering.trim(), + asSet(program.categories), + program.constraints?.trim() ?? "", + asSet(kinds), + asSet(territories.map(placeLabel)), + ]) + ) + .digest("hex") + .slice(0, 32); +} + +export interface FillShortlistArgs { + /** Candidates in the fixed ranking's order, best first. */ + queue: readonly ShortlistCandidate[]; + /** Places on the shortlist. */ + wanted: number; + /** One round of fit checks. An id it leaves out was not judged, and stays in. */ + judge: (batch: ShortlistCandidate[]) => Promise>; + /** + * Re-ranks who is left from the verdicts so far, over the queue's indexes. + * Null or absent: the fixed order. + */ + learner?: Pick | null; + /** + * How well a candidate sits in the segment's area, by queue index; a higher + * tier is worked through before a lower one is touched, as in the fixed + * order. Only read with a learner: the queue is already in that order. + */ + tierOf?: (index: number) => number; + /** Companies per round with a learner. */ + roundSize?: number; + /** Stop after this many checks; absent, until the list is full or nobody is left. */ + maxChecks?: number; +} + +export interface FillShortlistResult { + /** Every company the fit check was asked about, in the order it was asked. */ + checked: string[]; + /** The verdicts that came back, by id. */ + verdicts: Map; + /** Companies with no "no": judged a fit, or asked about and not answered for. */ + kept: number; + rounds: number; + /** Set when a round failed: everything seen before it stands. */ + error?: unknown; + /** + * Set when the learner had nobody to offer while companies were still + * waiting (numbers it could not rank): the fixed order took over from there. + */ + learnerQuit?: boolean; +} + +export async function fillShortlist(args: FillShortlistArgs): Promise { + const { queue, wanted } = args; + const learner = args.learner ?? null; + const roundSize = Math.max(1, args.roundSize ?? LEARNING_ROUND); + const maxChecks = args.maxChecks ?? Number.POSITIVE_INFINITY; + const result: FillShortlistResult = { checked: [], verdicts: new Map(), kept: 0, rounds: 0 }; + + const tierOf = args.tierOf; + const tiers = + learner && tierOf + ? [...new Set(queue.map((_, index) => tierOf(index)))].sort((a, b) => b - a) + : []; + let at = 0; + /** Queue indexes already asked about: the fixed order steps over them. */ + const asked = new Uint8Array(queue.length); + const downTheQueue = (count: number): number[] => { + const out: number[] = []; + for (; out.length < count && at < queue.length; at++) if (asked[at] === 0) out.push(at); + return out; + }; + /** The next companies to ask about, as queue indexes. */ + const pick = (count: number): number[] => { + if (!learner || result.learnerQuit) return downTheQueue(count); + const out: number[] = []; + if (!tierOf) out.push(...learner.next(count)); + else + for (const tier of tiers) { + if (out.length >= count) break; + out.push(...learner.next(count - out.length, index => tierOf(index) === tier)); + } + if (out.length > 0 || result.checked.length >= queue.length) return out; + // Companies are waiting and the learner offers none: it has numbers it + // cannot rank. The fit check must not stop for that. + result.learnerQuit = true; + return downTheQueue(count); + }; + + try { + // Until the shortlist is full or no one is left: a round of no's must + // not end the run with an empty list. + while (result.kept < wanted && result.checked.length < maxChecks) { + const room = wanted - result.kept; + const size = Math.min( + learner ? Math.min(roundSize, room * JUDGE_POOL_FACTOR) : room * JUDGE_POOL_FACTOR, + maxChecks - result.checked.length + ); + const indexes = pick(size); + if (indexes.length === 0) break; + for (const index of indexes) asked[index] = 1; + const batch = indexes.map(index => queue[index]!); + const answers = await args.judge(batch); + result.rounds += 1; + for (const [position, index] of indexes.entries()) { + const candidate = batch[position]!; + result.checked.push(candidate.id); + const verdict = answers.get(candidate.id); + if (verdict) result.verdicts.set(candidate.id, verdict); + if (verdict && !verdict.fit) { + learner?.observe(index, false); + continue; + } + result.kept += 1; + if (verdict) learner?.observe(index, true); + else learner?.skip(index); + } + } + } catch (error) { + result.error = error; + } + return result; +} diff --git a/pipelines/src/distribution/stages.test.ts b/pipelines/src/distribution/stages.test.ts index 23f2a7f80..c165f12d7 100644 --- a/pipelines/src/distribution/stages.test.ts +++ b/pipelines/src/distribution/stages.test.ts @@ -3,6 +3,7 @@ import { describe, expect, it } from "vitest"; import { ALLOWED_TRANSITIONS, assertTransition, + fitDecision, isInPipeline, stageRequirements, type StageTransitionError, @@ -158,6 +159,26 @@ describe("stage transition table", () => { }); }); +describe("what a deal's stage says about fit", () => { + it("reads qualifying, pursuing or winning a deal as a yes, Not a fit as a no, the rest as nothing", () => { + const by = Object.fromEntries( + RELATIONSHIP_STAGES.map(stage => [stage, fitDecision(stage)]) + ); + expect(by).toEqual({ + lead: null, + qualified: true, + contacted: true, + meeting: true, + proposal: true, + negotiating: true, + won: true, + // The stored stage the screens show as "Not a fit". + lost: false, + nurture: null, + }); + }); +}); + describe("legacy vocabulary", () => { it("maps every retired stage onto a stored one, the way the screens showed it", () => { expect(Object.keys(LEGACY_STAGE_MAP).sort()).toEqual( diff --git a/pipelines/src/distribution/stages.ts b/pipelines/src/distribution/stages.ts index 4c25ab19d..45518c11c 100644 --- a/pipelines/src/distribution/stages.ts +++ b/pipelines/src/distribution/stages.ts @@ -155,6 +155,18 @@ export function isPastCandidate(stage: RelationshipStage): boolean { return rank !== undefined && rank >= ORDER.get("contacted")!; } +/** + * What a person's handling of a deal says about whether the company fits the + * segment: a yes once they qualified, pursued or won it, a no when they marked + * it not a fit (the stored stage `lost`), and nothing while it is an untouched + * lead or parked in nurture. + */ +export function fitDecision(stage: RelationshipStage): boolean | null { + if (stage === "lost") return false; + if (stage === "lead" || stage === "nurture") return null; + return true; +} + /** Stages that count as "in pipeline" for the dashboard: past lead and not terminal. */ export function isInPipeline(stage: RelationshipStage): boolean { return stage !== "lead" && !TERMINAL_STAGES.has(stage); diff --git a/pipelines/src/distribution/types.ts b/pipelines/src/distribution/types.ts index c03a2a7b0..7e1fb3b77 100644 --- a/pipelines/src/distribution/types.ts +++ b/pipelines/src/distribution/types.ts @@ -242,6 +242,25 @@ export interface SourceCount { detail?: string; } +/** What the fit check of a run's candidates came to. */ +export interface FitCheckSummary { + /** Companies the fit check was asked about. */ + checked: number; + /** Rounds of asking. The fit check makes one model call per twenty companies of a round. */ + rounds: number; + /** Companies it judged would not buy this, or are elsewhere. */ + rejected: number; + /** The ranking re-ranked who was left after every round (./learn). */ + learning: boolean; + /** Verdicts known before the first round: earlier runs' and people's decisions. */ + startedFrom: number; + /** + * The check broke off on an error before the shortlist was full: the + * places it left open went to the next companies down the ranking, unchecked. + */ + incomplete?: boolean; +} + export interface RunSummary { sources: SourceCount[]; mentions: number; @@ -258,6 +277,8 @@ export interface RunSummary { warnings: string[]; tokens: { input: number; output: number; total: number }; wallMs?: number; + /** Absent on runs without a fit check, and on runs from before it was counted. */ + fitCheck?: FitCheckSummary; } export interface RunRecord { From 39f63682bfabd17851fdca5fdc678ccc2cab9770 Mon Sep 17 00:00:00 2001 From: Deodate-Lawson Date: Fri, 27 Nov 2026 13:58:17 -0500 Subject: [PATCH 3/3] Prospects: a no from research is kept under the question research asked The fit check after research asks a narrower question than the run's look at the listings: would this company buy as the one kind of buyer, in the one area, it was filed under? Its verdict was kept under the run's key all the same. On a segment with several buyer kinds or areas, a no to one of them was then taken for the segment's answer (a company filed under the segment's first area may sit in its second): it replaced the listing's verdict, taught the next run's ranking a no, and a later look at the listing could not correct it. Now the verdict is kept under the question it answers (researchVerdictKey in src/distribution/shortlist.ts): - A yes goes under the run's key. A yes to one kind in one area is a yes to a run that asked for them among others. - A no goes under the narrower question's own key, where only a run that asks that same question reads it. So does a yes to a kind or area the run did not ask for. - A run that asks for one kind in one area has the same key both ways, so nothing changes there. Found by the automated review on the pull request. Tests: four unit tests for the key, and a test against a real database on a segment with two buyer kinds, which fails on the code before this change. Co-Authored-By: Claude Fable 5.2 --- .changeset/prospects-shortlist-learns.md | 7 +- .../fit-verdicts.integration.test.ts | 128 +++++++++++++++++- pipelines/src/distribution/run.ts | 17 ++- pipelines/src/distribution/shortlist.test.ts | 66 ++++++++- pipelines/src/distribution/shortlist.ts | 35 +++++ 5 files changed, 245 insertions(+), 8 deletions(-) diff --git a/.changeset/prospects-shortlist-learns.md b/.changeset/prospects-shortlist-learns.md index fcd249908..eb6629a02 100644 --- a/.changeset/prospects-shortlist-learns.md +++ b/.changeset/prospects-shortlist-learns.md @@ -20,7 +20,12 @@ The Prospects fit check learns as it goes, and a run keeps what it learned. deals to (`fitDecision`). The fit check's verdicts are kept under the question they answered (`segmentKey`: offering, categories, constraints, buyer kinds and area, as the run narrowed them), so a segment that was - rewritten or moved starts afresh. People's decisions always count. + rewritten or moved starts afresh. The check after research asks about the + one kind of buyer and the one area a company was filed under: its yes is + kept under the run's key, its no under that narrower question's own key + (`researchVerdictKey`), so on a segment with several kinds or areas a no to + one of them is not taken for the segment's answer. People's decisions + always count. - A fit check that breaks off part-way no longer leaves a shortlist of only the companies it got through: the places it left open go to the next companies down the ranking, unchecked. A company named outside the diff --git a/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts b/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts index a80bf962b..508bd25e3 100644 --- a/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts +++ b/apps/web/__tests__/prospects/fit-verdicts.integration.test.ts @@ -3,8 +3,9 @@ * database: the fit check's verdicts (one row per company, research outranks * a later look at the listing), people's own decisions read from the stage of * the deal, a second run of a segment that starts from what the first one - * learned, and a segment whose area moved, which starts the fit check's - * verdicts afresh. Gated like the other integration suites. + * learned, research's narrower no on a segment with two kinds of buyer, and a + * segment whose area moved, which starts the fit check's verdicts afresh. + * Gated like the other integration suites. */ import { eq } from "drizzle-orm"; @@ -431,6 +432,129 @@ describeDb("fit verdicts between runs", () => { }); }); + it("keeps research's no about one kind of buyer apart from the whole segment's answer", async () => { + // A segment that sells to two kinds of buyer: the run asks the listings about both, + // research asks about the one kind each company was filed under. + const program = await createProgram({ + companyId, + userId: "u1", + input: { + name: "Two kinds", + offering: "Picking robots for fulfilment warehouses", + categories: ["fulfilment"], + hsCodes: [], + targetTerritories: [{ country: "NL" }], + partnerKinds: ["distributor", "retailer"], + constraints: null, + knownPartnerDomains: [], + customerDomains: [], + }, + }); + const run = await createRun({ + companyId, + programId: program.id, + userId: "u1", + options: { maxCandidates: 25, mode: "live" }, + }); + const ctx = { runId: run.id, companyId, programId: program.id }; + const prepared = await prepareRun(ctx, ports(pool("Kinds"), [])); + const runKey = segmentKey(program, run.options); + + const partners = await listPartners(companyId, { programId: program.id }); + const [ruledOut, confirmed] = prepared.candidateRelationshipIds + .slice(0, 2) + .map(id => partners.find(item => item.relationship.id === id)!); + const askedKey = (partner: (typeof partners)[number]) => + segmentKey(program, { + partnerKinds: [partner.relationship.kind], + territories: partner.relationship.territory + ? [partner.relationship.territory] + : undefined, + }); + expect(askedKey(ruledOut!)).not.toBe(runKey); + + const research = (fit: boolean): DistributionPorts => ({ + ...ports([], []), + profile: async () => ({ + outcome: { status: "gate_failed", dossier: null, errors: [] }, + evidence: [], + fetchedUrls: [], + turns: 0, + usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 }, + playbookHash: "test", + promptVersion: "test", + }), + judgeFit: async ({ candidates }) => + new Map( + candidates.map(c => [ + c.id, + { fit, reason: fit ? "Buys these." : "Not a distributor." }, + ]) + ), + }); + await enrichCandidate(ctx, research(false), { + relationshipId: ruledOut!.relationship.id, + profile: prepared.profile, + }); + await enrichCandidate(ctx, research(true), { + relationshipId: confirmed!.relationship.id, + profile: prepared.profile, + }); + + const rowOf = async (partner: (typeof partners)[number]) => { + const rows = await testDb.db + .select() + .from(distributionFitVerdicts) + .where(eq(distributionFitVerdicts.programId, program.id)); + return rows.find(row => row.resolveKey === partner.org.resolveKey)!; + }; + // The no says "not as this kind, here": kept under that question, not the run's. + expect(await rowOf(ruledOut!)).toMatchObject({ + basis: "research", + fit: false, + segmentKey: askedKey(ruledOut!), + }); + // The yes holds for the run's wider question too. + expect(await rowOf(confirmed!)).toMatchObject({ + basis: "research", + fit: true, + segmentKey: runKey, + }); + + // The next run of the whole segment starts from the yes and knows nothing of the no. + const known = await listFitExamples({ + companyId, + programId: program.id, + segmentKey: runKey, + }); + const by = new Map(known.map(e => [e.resolveKey, e])); + expect(by.has(ruledOut!.org.resolveKey)).toBe(false); + expect(by.get(confirmed!.org.resolveKey)).toMatchObject({ source: "research", good: true }); + + // And its look at the listing counts again: the narrower no does not stand in its way. + await saveFitVerdicts({ + companyId, + programId: program.id, + runId: run.id, + basis: "listing", + segmentKey: runKey, + verdicts: [ + { + resolveKey: ruledOut!.org.resolveKey, + name: ruledOut!.org.name, + text: `${ruledOut!.org.name}. ${OPERATOR}`, + fit: true, + reason: "Runs a warehouse.", + }, + ], + }); + expect(await rowOf(ruledOut!)).toMatchObject({ + basis: "listing", + fit: true, + segmentKey: runKey, + }); + }); + it("starts the fit check's verdicts afresh when the area moves, and still counts people's decisions", async () => { const program = await newProgram("Moved area"); const start = async (companies: CompanyHit[]) => { diff --git a/pipelines/src/distribution/run.ts b/pipelines/src/distribution/run.ts index 449f4e78e..0f8c78aab 100644 --- a/pipelines/src/distribution/run.ts +++ b/pipelines/src/distribution/run.ts @@ -53,7 +53,7 @@ import { type JudgeFit, type Relevance, } from "./semantic"; -import { fillShortlist, segmentKey } from "./shortlist"; +import { fillShortlist, researchVerdictKey, segmentKey } from "./shortlist"; import type { DiscoveryPlan, FitCheckSummary, @@ -871,8 +871,11 @@ export async function enrichCandidate( console.info(`${LOG_PREFIX} research ruled out ${org.name}: ${verdict.reason}`); } // What research found outranks the look at the listing: the next - // run's ranking learns from it, under the listing's own words and - // the key this run's listing verdicts are kept under. + // run's ranking learns from it, under the listing's own words. The + // question above is narrower than the run's (this one kind, in + // this one area), so the verdict is kept under the question it + // answers: a yes under the key this run's listing verdicts are + // kept under, a no under the narrower question's own key. if (verdict) await db .getRun(ctx.runId, ctx.companyId) @@ -882,7 +885,13 @@ export async function enrichCandidate( programId: ctx.programId, runId: ctx.runId, basis: "research", - segmentKey: segmentKey(program, run?.options), + segmentKey: researchVerdictKey({ + program, + run: run?.options, + kind: relationship.kind, + territory: relationship.territory, + fit: verdict.fit, + }), verdicts: [ { resolveKey: org.resolveKey, diff --git a/pipelines/src/distribution/shortlist.test.ts b/pipelines/src/distribution/shortlist.test.ts index 5e9b13ee3..e0c90b36c 100644 --- a/pipelines/src/distribution/shortlist.test.ts +++ b/pipelines/src/distribution/shortlist.test.ts @@ -2,7 +2,13 @@ import { describe, expect, it } from "vitest"; import { createShortlistLearner } from "./learn"; import type { FitVerdict } from "./semantic"; -import { fillShortlist, LEARNING_ROUND, segmentKey, type ShortlistCandidate } from "./shortlist"; +import { + fillShortlist, + LEARNING_ROUND, + researchVerdictKey, + segmentKey, + type ShortlistCandidate, +} from "./shortlist"; import type { PartnerKind } from "./types"; const candidates = (count: number): ShortlistCandidate[] => @@ -86,6 +92,64 @@ describe("segmentKey", () => { }); }); +describe("researchVerdictKey", () => { + const segment = { + offering: "Picking robots for fulfilment warehouses", + categories: ["fulfilment", "3PL"], + constraints: null, + partnerKinds: ["distributor", "retailer"] as PartnerKind[], + targetTerritories: [{ country: "NL" }, { country: "BE", region: "Flanders" }], + }; + const netherlands = { country: "NL" }; + const distributor: PartnerKind = "distributor"; + /** What research asked about: a distributor in the Netherlands. */ + const narrower = segmentKey(segment, { + partnerKinds: [distributor], + territories: [netherlands], + }); + + it("is the run's key either way when the run asks for one kind in one area", () => { + const run = { partnerKinds: [distributor], territories: [netherlands] }; + const asked = { program: segment, run, kind: distributor, territory: netherlands }; + expect(segmentKey(segment, run)).toBe(narrower); + expect(researchVerdictKey({ ...asked, fit: true })).toBe(narrower); + expect(researchVerdictKey({ ...asked, fit: false })).toBe(narrower); + }); + + it("keeps a yes under the run's wider key and a no under the narrower question's", () => { + // The run asks for both kinds in both areas. + const asked = { program: segment, kind: distributor, territory: netherlands }; + expect(narrower).not.toBe(segmentKey(segment)); + expect(researchVerdictKey({ ...asked, fit: true })).toBe(segmentKey(segment)); + expect(researchVerdictKey({ ...asked, fit: false })).toBe(narrower); + // A run over one kind in both areas is still wider than what research asked. + const run = { partnerKinds: [distributor] }; + expect(segmentKey(segment, run)).not.toBe(narrower); + expect(researchVerdictKey({ ...asked, run, fit: true })).toBe(segmentKey(segment, run)); + expect(researchVerdictKey({ ...asked, run, fit: false })).toBe(narrower); + }); + + it("keeps a yes the run did not ask about under the narrower question's key", () => { + const asked = { program: segment, kind: distributor, territory: netherlands }; + // Filed under the Netherlands by an earlier run, researched again by a run for Flanders. + const elsewhere = { territories: [{ country: "BE", region: "Flanders" }] }; + expect(researchVerdictKey({ ...asked, run: elsewhere, fit: true })).toBe(narrower); + // Filed as a distributor, researched again by a run for retailers. + const otherKind = { partnerKinds: ["retailer"] as PartnerKind[] }; + expect(researchVerdictKey({ ...asked, run: otherKind, fit: true })).toBe(narrower); + }); + + it("takes all the segment's areas as asked when the relationship has none", () => { + const asked = { program: segment, kind: distributor, territory: null }; + const allAreas = segmentKey(segment, { partnerKinds: [distributor] }); + expect(researchVerdictKey({ ...asked, fit: false })).toBe(allAreas); + // A yes for "in any of the areas" answers a run over all of them, not a run over one. + expect(researchVerdictKey({ ...asked, fit: true })).toBe(segmentKey(segment)); + const oneArea = { territories: [netherlands] }; + expect(researchVerdictKey({ ...asked, run: oneArea, fit: true })).toBe(allAreas); + }); +}); + describe("fillShortlist with the fixed ranking", () => { it("checks twice the open places per round, down the list, until the list is full", async () => { const { judge, rounds } = judgeBy(id => Number(id.slice(1)) % 2 === 0); diff --git a/pipelines/src/distribution/shortlist.ts b/pipelines/src/distribution/shortlist.ts index 88b6a9e9b..39d9c03f1 100644 --- a/pipelines/src/distribution/shortlist.ts +++ b/pipelines/src/distribution/shortlist.ts @@ -74,6 +74,41 @@ export function segmentKey( .slice(0, 32); } +/** + * The key a verdict of the fit check after research is kept under. That check + * asks a narrower question than the run's look at the listings: would this + * company buy as the one kind of buyer, in the one area, it was filed under? + * + * A yes to that is a yes to every question that asks for that kind and area + * among others, so it is kept under the run's key and the next run of the + * segment starts from it. A no rules out that kind in that area and nothing + * more (a company filed under the segment's first area may sit in its + * second), so it is kept under the narrower question's own key, where it + * cannot stand in for the segment's answer. So is a yes to a kind or area the + * run did not ask for. A run that asks for one kind in one area has the same + * key both ways. + */ +export function researchVerdictKey(args: { + program: Parameters[0]; + /** The run's own narrowing of the segment (its options), when it has one. */ + run?: Parameters[1]; + /** What the check after research asked about: the relationship's kind and area. */ + kind: PartnerKind; + territory: Territory | null; + fit: boolean; +}): string { + const { program, run, kind, territory } = args; + // With no area on the relationship the check names all of the segment's. + const askedTerritories = territory ? [territory] : program.targetTerritories; + const asked = segmentKey(program, { partnerKinds: [kind], territories: askedTerritories }); + if (!args.fit) return asked; + const kinds = run?.partnerKinds?.length ? run.partnerKinds : program.partnerKinds; + const territories = run?.territories?.length ? run.territories : program.targetTerritories; + const places = new Set(territories.map(placeLabel)); + const within = kinds.includes(kind) && askedTerritories.every(t => places.has(placeLabel(t))); + return within ? segmentKey(program, run) : asked; +} + export interface FillShortlistArgs { /** Candidates in the fixed ranking's order, best first. */ queue: readonly ShortlistCandidate[];