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

fix: Read embedder URL from env #9936

Merged
merged 1 commit into from
Jul 4, 2024
Merged
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
21 changes: 16 additions & 5 deletions packages/server/graphql/public/types/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ import {UserResolvers} from '../resolverTypes'

declare const __PRODUCTION__: string

const MODEL = 'Embeddings_ember_1'
const EMBED_URL = (() => {
try {
const availableModels =
process.env.AI_EMBEDDING_MODELS && JSON.parse(process.env.AI_EMBEDDING_MODELS)
return availableModels.find(
({model}: {model?: string}) => model?.split(':')[1] === 'llmrails/ember-v1'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Dschoordsch why is llmrails/ember-v1 hardcoded? That's just a possibility but in the future we might have other thing there. I might be lacking of JS knowledge to read this expression 😺

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it's hardcoded. It's also hardcoded here:

I tried to strike the balance between getting stuff out now vs. making it future proof. Even if we add more models, we would need to test which one to use here and adjust accordingly. Having it configurable via environment for example add some complexity which might never be needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaking, on that file TextEmbeddingsInference.ts you have that model but there is another one there too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm not mistaking, on that file TextEmbeddingsInference.ts you have that model but there is another one there too.

)?.url
} catch {
return undefined
}
})()
const SIMILARITY_THRESHOLD = 0.5

const User: UserResolvers = {
activity: async (_source, {activityId}, {dataLoader}) => {
const activity = await dataLoader.get('meetingTemplates').load(activityId)
Expand Down Expand Up @@ -186,7 +200,7 @@ const User: UserResolvers = {
return connectionFromTemplateArray(allActivities, first, after)
},
templateSearch: async ({id: userId}, {search}, {authToken, dataLoader}) => {
if (!search) return []
if (!search || !EMBED_URL) return []
const viewerId = getUserId(authToken)
const user = await dataLoader.get('users').loadNonNull(userId)
const teamIds =
Expand All @@ -203,16 +217,13 @@ const User: UserResolvers = {
// all team ids which could have accessible templates
const allTeamIds = ['aGhostTeam', ...allOrgTeams.map(({id}) => id)]

const response = await fetch('http://localhost:3040/embed', {
const response = await fetch(EMBED_URL, {
method: 'POST',
body: JSON.stringify({inputs: search}),
headers: {'Content-Type': 'application/json'}
})
const data = await response.json()

const MODEL = 'Embeddings_ember_1'
const SIMILARITY_THRESHOLD = 0.5

const pg = getKysely()
const similarEmbeddings = await pg
.with('Model', (qc) =>
Expand Down
Loading