Skip to content

Commit 30637ef

Browse files
committed
fix: handle embedOnly param in visual-search API, use deployed API base
- Visual-search endpoint now checks for embedOnly:true in request body and returns just the embedding vector instead of running a DB search - Embed script uses configurable API_BASE env var (default toil.fyi)
1 parent a382d33 commit 30637ef

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

functions/api/visual-search.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,33 @@ export async function onRequest(context: {
5151
}
5252

5353
try {
54-
const { description } = (await request.json()) as { description: string };
54+
const body = (await request.json()) as {
55+
description: string;
56+
embedOnly?: boolean;
57+
};
5558

56-
if (!description || description.length < 3) {
59+
if (!body.description || body.description.length < 3) {
5760
return new Response('Description too short', { status: 400 });
5861
}
5962

6063
let queryEmbedding: number[] = [];
6164

6265
if (env.AI) {
6366
const result = await env.AI.run('@cf/baai/bge-base-en-v1.5', {
64-
text: [description],
67+
text: [body.description],
6568
});
6669
queryEmbedding = result.data[0];
6770
}
6871

72+
if (body.embedOnly) {
73+
return new Response(JSON.stringify({ embedding: queryEmbedding }), {
74+
headers: {
75+
'Content-Type': 'application/json',
76+
'Access-Control-Allow-Origin': '*',
77+
},
78+
});
79+
}
80+
6981
const { results } = await env.DB.prepare(
7082
'SELECT preset_id, embedding FROM preset_embeddings',
7183
).all<{ preset_id: string; embedding: string }>();

0 commit comments

Comments
 (0)