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

Support using Embeddings Model exposed via OpenAI (compatible) API #1051

Merged
merged 2 commits into from
Jan 15, 2025

Conversation

debanjum
Copy link
Member

@debanjum debanjum commented Jan 9, 2025

This change adds the ability to use OpenAI's embedding models or any embedding model exposed behind an OpenAI compatible API (like Ollama, LiteLLM, vLLM etc.). This allows using commercial embedding models to index your content with Khoj.

Khoj previously only supported HuggingFace embedding models running locally on device or via HuggingFaceW inference API endpoint.

@debanjum debanjum force-pushed the support-azure-openai-api-endpoint branch from e057838 to 275d70e Compare January 9, 2025 03:42
@debanjum debanjum force-pushed the support-embbedings-model-via-openai-api branch from 1189679 to cc82667 Compare January 9, 2025 03:45
@debanjum debanjum force-pushed the support-azure-openai-api-endpoint branch from 275d70e to f6948a2 Compare January 9, 2025 03:48
@debanjum debanjum force-pushed the support-embbedings-model-via-openai-api branch 2 times, most recently from 89a0e28 to d186eed Compare January 9, 2025 05:26
Base automatically changed from support-azure-openai-api-endpoint to master January 10, 2025 16:41
@debanjum debanjum force-pushed the support-embbedings-model-via-openai-api branch from d186eed to 1b5826d Compare January 10, 2025 16:48
Copy link
Member

@sabaimran sabaimran left a comment

Choose a reason for hiding this comment

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

Sweet! This should definitely help Khoj be more scale-ready for generating embeddings.

src/khoj/processor/embeddings.py Show resolved Hide resolved
src/khoj/database/models/__init__.py Show resolved Hide resolved
src/khoj/database/models/__init__.py Show resolved Hide resolved
@debanjum debanjum merged commit 63dd398 into master Jan 15, 2025
9 of 10 checks passed
@debanjum debanjum deleted the support-embbedings-model-via-openai-api branch January 15, 2025 10:40
@jppaolim
Copy link

sounds amazing. But it doesn't seem to be actually indexing via the API. I used the MD file which is not yet merged, adding text-embedding-3-small to the name of biencoder, and inputing and API key. Shall I do something else ? How to make sure it works. ?

@debanjum
Copy link
Member Author

Hey could you follow these instructions.

Two things to remember to do:

  1. On the Admin panel, ensure only the Search Model Config for the OpenAI embeddings has the name default.
  2. Restart your Khoj server before trying to index you md files

If it's still not working, it'd be good if you can share screenshots of your OpenAI Search Model admin config page and the top level search model config page from the admin panel that lists all the search model configs

@jppaolim
Copy link

jppaolim commented Jan 21, 2025

Studying the log, I had passed https://api.openai.com/v1/embeddings and not https://api.openai.com/v1 as endpoint.
it seems to embed correctly. Then I had to adjust the treshold, I didn't perform extensive tests, but 0,18 was too low. I put 0,5 and it works for text-embedding-3-small. Further guidance will be welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants