Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions graphile/graphile-llm/src/__tests__/embed-inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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'; });

Expand Down
7 changes: 5 additions & 2 deletions graphile/graphile-llm/src/plugins/text-mutation-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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,
Expand Down
Loading