|
| 1 | +# `'jupyter_ai.embeddings_model_providers'` |
| 2 | + |
| 3 | +```{contents} Contents |
| 4 | +``` |
| 5 | + |
| 6 | +## Summary |
| 7 | + |
| 8 | +This entry point group allows packages to add custom embedding model providers |
| 9 | +to power the retrieval-augmented generation (RAG) capabilities of Jupyter AI. |
| 10 | + |
| 11 | +This group expects an **embedding model provider class**, a subclass of |
| 12 | +`BaseEmbeddingsProvider` from `jupyter-ai` that also inherits from an |
| 13 | +`Embeddings` class from LangChain. Instructions on defining one are given in the |
| 14 | +next section. |
| 15 | + |
| 16 | +:::{warning} |
| 17 | +This is a v2 extension point that may be removed in v3. In v3, we may explore |
| 18 | +updating the model API to make it easier for developers to add custom models. |
| 19 | +::: |
| 20 | + |
| 21 | +## How-to: Define a custom embedding model provider |
| 22 | + |
| 23 | +```python |
| 24 | +from jupyter_ai_magics import BaseEmbeddingsProvider |
| 25 | +from langchain.embeddings import FakeEmbeddings |
| 26 | + |
| 27 | +class MyEmbeddingsProvider(BaseEmbeddingsProvider, FakeEmbeddings): |
| 28 | + id = "my_embeddings_provider" |
| 29 | + name = "My Embeddings Provider" |
| 30 | + model_id_key = "model" |
| 31 | + models = ["my_model"] |
| 32 | + |
| 33 | + def __init__(self, **kwargs): |
| 34 | + super().__init__(size=300, **kwargs) |
| 35 | +``` |
| 36 | + |
| 37 | +Jupyter AI uses entry points to discover embedding providers. |
| 38 | +In the `pyproject.toml` file, add your custom embedding provider to the |
| 39 | +`[project.entry-points."jupyter_ai.embeddings_model_providers"]` section: |
| 40 | + |
| 41 | +```toml |
| 42 | +[project.entry-points."jupyter_ai.embeddings_model_providers"] |
| 43 | +my-provider = "my_provider:MyEmbeddingsProvider" |
| 44 | +``` |
| 45 | + |
| 46 | +[Embeddings]: https://api.python.langchain.com/en/stable/embeddings/langchain_core.embeddings.Embeddings.html |
0 commit comments