diff --git a/graphile/graphile-llm/src/__tests__/embed-inputs.test.ts b/graphile/graphile-llm/src/__tests__/embed-inputs.test.ts index 2a4fb256f6..66a2247e93 100644 --- a/graphile/graphile-llm/src/__tests__/embed-inputs.test.ts +++ b/graphile/graphile-llm/src/__tests__/embed-inputs.test.ts @@ -79,6 +79,12 @@ const SETUP_SQL = ` ('warehouse-lease.txt', 'warehouse lease and monthly rent', '[1,0,0]'), ('q3-results.txt', 'quarterly revenue results', '[0,1,0]'), ('breach-report.txt', 'customer data breach', '[0,0,1]'); + CREATE TABLE llm_embed_inputs.frozen_docs ( + id serial PRIMARY KEY, + name text NOT NULL, + embedding vector(3) + ); + COMMENT ON COLUMN llm_embed_inputs.frozen_docs.embedding IS E'@behavior -attribute:update'; `; interface Harness { @@ -192,6 +198,23 @@ describe('plan-time embedding (onQuotaExceeded: degrade)', () => { expect(errors).toEqual([[], [], []]); }); + it('offers {col}Text only on inputs that can write {col}', async () => { + const fields = async (type: string) => { + const r = await h.query<{ t: { inputFields: Array<{ name: string }> } }>( + `{ t: __type(name: "${type}") { inputFields { name } } }` + ); + return r.data!.t.inputFields.map((f) => f.name).filter((n) => n.startsWith('embedding')); + }; + expect(await fields('FrozenDocInput')).toEqual(['embedding', 'embeddingText']); + expect(await fields('FrozenDocPatch')).toEqual([]); + + const update = await h.query( + 'mutation { updateFrozenDocByRowId(input: { rowId: 1, frozenDocPatch: { embeddingText: "rent" } }) { frozenDoc { rowId } } }' + ); + expect(update.errors?.[0]?.message).toMatch(/embeddingText/); + expect(calls).toHaveLength(0); + }); + describe('embedder returning the provider shape', () => { beforeEach(() => { shape = 'result'; }); diff --git a/graphile/graphile-llm/src/plugins/text-mutation-plugin.ts b/graphile/graphile-llm/src/plugins/text-mutation-plugin.ts index d5847645a6..9f2a847021 100644 --- a/graphile/graphile-llm/src/plugins/text-mutation-plugin.ts +++ b/graphile/graphile-llm/src/plugins/text-mutation-plugin.ts @@ -2,7 +2,7 @@ * LlmTextMutationPlugin * * Adds `{columnName}Text: String` companion fields on create/update mutation - * inputs for every vector column. When the client provides a text string in + * inputs that carry the vector column's own field. When the client provides a text string in * the companion field, the plugin embeds it server-side and injects the * resulting vector into the actual column. * @@ -144,7 +144,10 @@ export function createLlmTextMutationPlugin(): GraphileConfig.Plugin { } const vectorField = newFields[fieldName]; - const required = !!vectorField && isNonNullType(vectorField.type); + if (!vectorField) { + continue; + } + const required = isNonNullType(vectorField.type); if (required) { newFields = { ...newFields,