Skip to content

Commit 9f62f21

Browse files
pescnclaude
andcommitted
feat(api): add model filter to embeddings API and fix history navigation
Add model name filter to embeddings API (similar to completions API) and fix the history button in models registry to navigate to the correct page based on model type. Changes: - Add `model` parameter to `listEmbeddings` function with LIKE query - Add `model` query parameter to GET /admin/embeddings endpoint - Add `model` to frontend embeddings route search schema - Update history button to navigate to /embeddings for embedding models and /requests for chat models Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 9267ceb commit 9f62f21

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

backend/src/api/admin/embeddings.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ export const adminEmbeddings = new Elysia({ prefix: "/embeddings" })
1111
.get(
1212
"/",
1313
async ({ query }) => {
14-
const { offset, limit, apiKeyId, modelId } = query;
14+
const { offset, limit, apiKeyId, modelId, model } = query;
1515
const result = await listEmbeddings(
1616
offset ?? 0,
1717
limit ?? 20,
1818
apiKeyId,
1919
modelId,
20+
model,
2021
);
2122
return result;
2223
},
@@ -26,6 +27,7 @@ export const adminEmbeddings = new Elysia({ prefix: "/embeddings" })
2627
limit: t.Optional(t.Numeric()),
2728
apiKeyId: t.Optional(t.Numeric()),
2829
modelId: t.Optional(t.Numeric()),
30+
model: t.Optional(t.String()),
2931
}),
3032
detail: {
3133
description: "List embedding requests (paginated)",

backend/src/db/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,9 @@ export async function listEmbeddings(
930930
limit: number,
931931
apiKeyId?: number,
932932
modelId?: number,
933+
model?: string,
933934
): Promise<PartialList<Embedding>> {
934-
logger.debug("listEmbeddings", offset, limit, apiKeyId, modelId);
935+
logger.debug("listEmbeddings", offset, limit, apiKeyId, modelId, model);
935936
const sq = db
936937
.select({ id: schema.EmbeddingsTable.id })
937938
.from(schema.EmbeddingsTable)
@@ -940,6 +941,7 @@ export async function listEmbeddings(
940941
not(schema.EmbeddingsTable.deleted),
941942
apiKeyId ? eq(schema.EmbeddingsTable.apiKeyId, apiKeyId) : undefined,
942943
modelId ? eq(schema.EmbeddingsTable.modelId, modelId) : undefined,
944+
model ? like(schema.EmbeddingsTable.model, `${model}%`) : undefined,
943945
),
944946
)
945947
.orderBy(desc(schema.EmbeddingsTable.id))
@@ -961,6 +963,7 @@ export async function listEmbeddings(
961963
not(schema.EmbeddingsTable.deleted),
962964
apiKeyId ? eq(schema.EmbeddingsTable.apiKeyId, apiKeyId) : undefined,
963965
modelId ? eq(schema.EmbeddingsTable.modelId, modelId) : undefined,
966+
model ? like(schema.EmbeddingsTable.model, `${model}%`) : undefined,
964967
),
965968
);
966969

frontend/src/pages/settings/models-settings-page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ function ModelRow({ systemName }: { systemName: string }) {
8585

8686
const handleHistoryClick = (e: React.MouseEvent) => {
8787
e.stopPropagation()
88-
navigate({ to: '/requests', search: { model: systemName } })
88+
if (modelType === 'embedding') {
89+
navigate({ to: '/embeddings', search: { model: systemName } })
90+
} else {
91+
navigate({ to: '/requests', search: { model: systemName } })
92+
}
8993
}
9094

9195
return (

frontend/src/routes/embeddings/index.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,21 @@ const embeddingsSearchSchema = z.object({
1717
pageSize: z.number().catch(20),
1818
apiKeyId: z.number().optional(),
1919
modelId: z.number().optional(),
20+
model: z.string().optional(),
2021
selectedEmbeddingId: z.number().optional(),
2122
})
2223

2324
type EmbeddingsSearchSchema = z.infer<typeof embeddingsSearchSchema>
2425

25-
const embeddingsQueryOptions = ({ page, pageSize, apiKeyId, modelId }: EmbeddingsSearchSchema) =>
26+
const embeddingsQueryOptions = ({ page, pageSize, apiKeyId, modelId, model }: EmbeddingsSearchSchema) =>
2627
queryOptions({
27-
queryKey: ['embeddings', { page, pageSize, apiKeyId, modelId }],
28+
queryKey: ['embeddings', { page, pageSize, apiKeyId, modelId, model }],
2829
queryFn: async () => {
2930
const { data: rawData, error } = await api.admin.embeddings.get({
3031
query: {
3132
offset: (page - 1) * pageSize,
3233
limit: pageSize,
33-
...removeUndefinedFields({ apiKeyId, modelId }),
34+
...removeUndefinedFields({ apiKeyId, modelId, model }),
3435
},
3536
})
3637
if (error) throw formatError(error, i18n.t('routes.embeddings.index.FetchError'))
@@ -41,17 +42,17 @@ const embeddingsQueryOptions = ({ page, pageSize, apiKeyId, modelId }: Embedding
4142

4243
export const Route = createFileRoute('/embeddings/')({
4344
validateSearch: zodValidator(embeddingsSearchSchema),
44-
loaderDeps: ({ search: { page, pageSize, apiKeyId, modelId } }) => ({ page, pageSize, apiKeyId, modelId }),
45+
loaderDeps: ({ search: { page, pageSize, apiKeyId, modelId, model } }) => ({ page, pageSize, apiKeyId, modelId, model }),
4546
loader: ({ deps }) => queryClient.ensureQueryData(embeddingsQueryOptions(deps)),
4647
component: RouteComponent,
4748
errorComponent: AppErrorComponent,
4849
})
4950

5051
function RouteComponent() {
51-
const { page, pageSize, apiKeyId, modelId } = Route.useSearch()
52+
const { page, pageSize, apiKeyId, modelId, model } = Route.useSearch()
5253
const {
5354
data: { data, total },
54-
} = useSuspenseQuery(embeddingsQueryOptions({ page, pageSize, apiKeyId, modelId }))
55+
} = useSuspenseQuery(embeddingsQueryOptions({ page, pageSize, apiKeyId, modelId, model }))
5556

5657
return (
5758
<main className="flex h-[calc(100svh-3rem)] items-stretch">

0 commit comments

Comments
 (0)