Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: embedding server be dynamic per deployment #2244

Closed
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
131 changes: 87 additions & 44 deletions frontends/dashboard/src/components/NewDatasetModal.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Accessor, createMemo, createSignal, useContext, For } from "solid-js";
import {
Accessor,
createMemo,
createSignal,
createEffect,
useContext,
For,
Show,
} from "solid-js";
import { AiOutlineWarning } from "solid-icons/ai";
import {
Dialog,
DialogPanel,
Expand All @@ -12,7 +21,6 @@
import {
ServerEnvsConfiguration,
availableDistanceMetrics,
availableEmbeddingModels,
} from "shared/types";
import { defaultServerEnvsConfiguration } from "../pages/Dashboard/Dataset/DatasetSettingsPage";
import { createToast } from "./ShowToasts";
Expand All @@ -35,6 +43,20 @@
const [isLoading, setIsLoading] = createSignal(false);
const [fillWithExampleData, setFillWithExampleData] = createSignal(false);

const api_host = import.meta.env.VITE_API_HOST as unknown as string;

const [availableEmbeddingModels, setAvailableEmbeddingModels] =
createSignal<any>([]);

Check failure on line 49 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L49

[@typescript-eslint/no-explicit-any] Unexpected any. Specify a different type.

createEffect(() => {
fetch(`${api_host}/embedding_models`)
.then((resp) => resp.json())
.then((json) => {
console.log(json.models);

Check failure on line 55 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L55

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .models on an `any` value.
setAvailableEmbeddingModels(json.models);

Check failure on line 56 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L56

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .models on an `any` value.
});

Check failure on line 57 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L52-L57

[@typescript-eslint/no-floating-promises] Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.
});

const selectedOrgnaization = createMemo(() => {
const selectedOrgId = userContext.selectedOrganizationId?.();
if (!selectedOrgId) return null;
Expand Down Expand Up @@ -186,51 +208,72 @@
>
Embedding Model
</label>
<select
id="embeddingSize"
name="embeddingSize"
class="col-span-2 block w-full rounded-md border-[0.5px] border-neutral-300 bg-white px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
value={
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
availableEmbeddingModels.find(
(model) =>
<Show when={availableEmbeddingModels().length > 0}>

Check failure on line 211 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L211

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .length on an `any` value.
<select
id="embeddingSize"
name="embeddingSize"
class="col-span-2 block w-full rounded-md border-[0.5px] border-neutral-300 bg-white px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
value={
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
availableEmbeddingModels().find(
(model) =>
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
model.id ===
serverConfig().EMBEDDING_MODEL_NAME,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
model.id ===
serverConfig().EMBEDDING_MODEL_NAME,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
)?.name ?? availableEmbeddingModels[0].name
}
onChange={(e) => {
const selectedModel = availableEmbeddingModels.find(
(model) => model.name === e.currentTarget.value,
);
)?.display_name ??
availableEmbeddingModels()[0]?.display_name

Check failure on line 225 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L225

[@typescript-eslint/no-unsafe-member-access] Unsafe member access [0] on an `any` value.
}
onChange={(e) => {
const selectedModel =
availableEmbeddingModels()?.find(

Check failure on line 229 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L229

[@typescript-eslint/no-unsafe-call] Unsafe call of an `any` typed value.

Check failure on line 229 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L229

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .find on an `any` value.
(model) =>
model.display_name ===

Check failure on line 231 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L231

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .display_name on an `any` value.
e.currentTarget.value,
);

Check failure on line 233 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L228-L233

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.

const embeddingSize =
selectedModel?.dimension ?? 1536;
const embeddingSize =
selectedModel?.dimension ?? 1536;

Check failure on line 236 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L235-L236

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.

Check failure on line 236 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L236

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .dimension on an `any` value.

setServerConfig((prev) => {
return {
...prev,
EMBEDDING_SIZE: embeddingSize,
EMBEDDING_MODEL_NAME:
selectedModel?.id ?? "jina-base-en",
EMBEDDING_QUERY_PREFIX:
selectedModel?.id === "jina-base-en"
? "Search for:"
: "",
EMBEDDING_BASE_URL:
selectedModel?.url ??
"https://api.openai.com/v1",
};
});
}}
>
<For each={availableEmbeddingModels}>
{(model) => (
<option value={model.name}>{model.name}</option>
)}
</For>
</select>
setServerConfig((prev) => {
return {
...prev,
EMBEDDING_SIZE: embeddingSize,

Check failure on line 241 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L241

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.
EMBEDDING_MODEL_NAME:
selectedModel?.id ?? "jina-base-en",

Check failure on line 243 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L242-L243

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.

Check failure on line 243 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L243

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .id on an `any` value.
EMBEDDING_QUERY_PREFIX:
selectedModel?.id === "jina-base-en"

Check failure on line 245 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L245

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .id on an `any` value.
? "Search for:"
: "",
EMBEDDING_BASE_URL:
selectedModel?.url ??

Check failure on line 249 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L249

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .url on an `any` value.
"https://api.openai.com/v1",

Check failure on line 250 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L248-L250

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.
};
});
}}
>
<For each={availableEmbeddingModels()}>

Check failure on line 255 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L255

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.
{(model) => (
<option value={model.display_name}>

Check failure on line 257 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L257

[@typescript-eslint/no-unsafe-assignment] Unsafe assignment of an `any` value.

Check failure on line 257 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L257

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .display_name on an `any` value.
{model.display_name}

Check failure on line 258 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L258

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .display_name on an `any` value.
</option>
)}
</For>
</select>
</Show>
<Show when={availableEmbeddingModels().length == 0}>

Check failure on line 264 in frontends/dashboard/src/components/NewDatasetModal.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/components/NewDatasetModal.tsx#L264

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .length on an `any` value.
<div class="col-span-2 flex items-center space-x-2">
<AiOutlineWarning class="h-5 w-5 text-yellow-400" />
<div class="flex flex-col space-y-1">
<div class="w-full text-base text-neutral-800 sm:text-sm sm:leading-6">
No Embedding Models available
</div>
<div class="w-full text-xs">
Check server settings
</div>
</div>
</div>
</Show>
</div>

<div class="content-center py-4 sm:grid sm:grid-cols-3 sm:items-start sm:gap-4">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import {
ServerEnvsConfiguration,
availableDistanceMetrics,
availableEmbeddingModels,
} from "shared/types";
import { createToast } from "../../../components/ShowToasts";
import { AiOutlineInfoCircle } from "solid-icons/ai";
Expand Down Expand Up @@ -56,6 +55,20 @@
config: (prev: ServerEnvsConfiguration) => ServerEnvsConfiguration,
) => void;
}) => {
const api_host = import.meta.env.VITE_API_HOST as unknown as string;

const [availableEmbeddingModels, setAvailableEmbeddingModels] =
createSignal<any>([]);

Check failure on line 61 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L61

[@typescript-eslint/no-explicit-any] Unexpected any. Specify a different type.

createEffect(() => {
fetch(`${api_host}/embedding_models`)
.then((resp) => resp.json())
.then((json) => {
console.log(json.models);

Check failure on line 67 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L67

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .models on an `any` value.
setAvailableEmbeddingModels(json.models);

Check failure on line 68 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L68

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .models on an `any` value.
});

Check failure on line 69 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L64-L69

[@typescript-eslint/no-floating-promises] Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.
});

return (
<form class="flex flex-col gap-3">
{/* General LLM Settings */}
Expand Down Expand Up @@ -554,14 +567,18 @@
name="embeddingSize"
class="col-span-2 block w-full cursor-not-allowed rounded-md border-[0.5px] border-neutral-300 bg-white px-3 py-1.5 shadow-sm placeholder:text-neutral-400 focus:outline-magenta-500 sm:text-sm sm:leading-6"
value={
availableEmbeddingModels.find(
availableEmbeddingModels().find(

Check failure on line 570 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L570

[@typescript-eslint/no-unsafe-call] Unsafe call of an `any` typed value.

Check failure on line 570 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L570

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .find on an `any` value.
(model) =>
model.id === props.serverConfig().EMBEDDING_MODEL_NAME,

Check failure on line 572 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L572

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .id on an `any` value.
)?.name ?? availableEmbeddingModels[0].name
)?.display_name ?? availableEmbeddingModels()[0]?.display_name

Check failure on line 573 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L573

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .display_name on an `any` value.

Check failure on line 573 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L573

[@typescript-eslint/no-unsafe-member-access] Unsafe member access [0] on an `any` value.
}
>
<For each={availableEmbeddingModels}>
{(model) => <option value={model.name}>{model.name}</option>}
<For each={availableEmbeddingModels()}>
{(model) => (
<option value={model.display_name}>

Check failure on line 578 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L578

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .display_name on an `any` value.
{model.display_name}

Check failure on line 579 in frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

frontends/dashboard/src/pages/Dashboard/Dataset/DatasetSettingsPage.tsx#L579

[@typescript-eslint/no-unsafe-member-access] Unsafe member access .display_name on an `any` value.
</option>
)}
</For>
</select>
</div>
Expand Down Expand Up @@ -622,7 +639,7 @@
availableDistanceMetrics.find(
(metric) =>
metric.id === props.serverConfig().DISTANCE_METRIC,
)?.name ?? availableEmbeddingModels[0].name
)?.name ?? availableDistanceMetrics[0].name
}
>
<For each={availableDistanceMetrics}>
Expand Down
33 changes: 0 additions & 33 deletions frontends/dashboard/src/types/apiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,39 +256,6 @@ export interface ApiKeyRespBody {
updated_at: string;
}

export const availableEmbeddingModels = [
{
id: "jina-base-en",
name: "jina-base-en (securely hosted by Trieve)",
url: "https://embedding.trieve.ai",
dimension: 768,
},
{
id: "bge-m3",
name: "bge-m3 (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/bge-m3",
dimension: 1024,
},
{
id: "jina-embeddings-v2-base-code",
name: "jina-embeddings-v2-base-code (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/jina-code",
dimension: 768,
},
{
id: "text-embedding-3-small",
name: "text-embedding-3-small (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 1536,
},
{
id: "text-embedding-3-large",
name: "text-embedding-3-large (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 3072,
},
];

export interface EventDTO {
events: Event[];
page_count: number;
Expand Down
33 changes: 0 additions & 33 deletions frontends/shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,39 +266,6 @@ export interface ApiKeyRespBody {
updated_at: string;
}

export const availableEmbeddingModels = [
{
id: "jina-base-en",
name: "jina-base-en (securely hosted by Trieve)",
url: "https://embedding.trieve.ai",
dimension: 768,
},
{
id: "bge-m3",
name: "bge-m3 (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/bge-m3",
dimension: 1024,
},
{
id: "jina-embeddings-v2-base-code",
name: "jina-embeddings-v2-base-code (securely hosted by Trieve)",
url: "https://embedding.trieve.ai/jina-code",
dimension: 768,
},
{
id: "text-embedding-3-small",
name: "text-embedding-3-small (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 1536,
},
{
id: "text-embedding-3-large",
name: "text-embedding-3-large (hosted by OpenAI)",
url: "https://api.openai.com/v1",
dimension: 3072,
},
];

export const availableDistanceMetrics = [
{
id: "cosine",
Expand Down
52 changes: 52 additions & 0 deletions server/src/handlers/chunk_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2661,3 +2661,55 @@ pub fn check_completion_param_validity(

Ok(())
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
pub struct AvailableModelResponse {
models: Vec<EmbeddingModel>,
}

#[derive(Serialize, Deserialize, Debug, Clone, ToSchema)]
pub struct EmbeddingModel {
id: String,
display_name: String,
url: String,
dimension: u32,
}

pub async fn get_available_models() -> Result<HttpResponse, ServiceError> {
let avail_models = AvailableModelResponse {
models: vec![
EmbeddingModel {
id: "jina-base-en".into(),
display_name: "jina-base-en (securely hosted by Trieve)".into(),
url: "https://embedding.trieve.ai".into(),
dimension: 768,
},
EmbeddingModel {
id: "bge-m3".into(),
display_name: "bge-m3 (securely hosted by Trieve)".into(),
url: "https://embedding.trieve.ai/bge-m3".into(),
dimension: 1024,
},
EmbeddingModel {
id: "jina-embeddings-v2-base-code".into(),
display_name: "jina-embeddings-v2-base-code (securely hosted by Trieve)".into(),
url: "https://embedding.trieve.ai/jina-code".into(),
dimension: 768,
},
EmbeddingModel {
id: "text-embedding-3-small".into(),
display_name: "text-embedding-3-small (hosted by OpenAI)".into(),
url: "https://api.openai.com/v1".into(),
dimension: 1536,
},
EmbeddingModel {
id: "text-embedding-3-large".into(),
display_name: "text-embedding-3-large (hosted by OpenAI)".into(),
url: "https://api.openai.com/v1".into(),
dimension: 3072,
},
],
};

Ok(HttpResponse::Ok().json(avail_models))
}
3 changes: 3 additions & 0 deletions server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,9 @@ pub fn main() -> std::io::Result<()> {
.route(web::put().to(handlers::analytics_handler::send_ctr_data))
.route(web::post().to(handlers::analytics_handler::get_ctr_analytics)),
)
).service(
web::resource("/embedding_models")
.route(web::get().to(handlers::chunk_handler::get_available_models))
),
)
})
Expand Down
Loading