123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- ---
- title: '📱 App types'
- ---
- ## App Types
- Embedchain supports a variety of LLMs, embedding functions/models and vector databases.
- Our app gives you full control over which components you want to use, you can mix and match them to your hearts content.
- <Tip>
- Out of the box, if you just use `app = App()`, Embedchain uses what we believe to be the best configuration available. This might include paid/proprietary components. Currently, this is
- * LLM: OpenAi (gpt-3.5-turbo)
- * Embedder: OpenAi (text-embedding-ada-002)
- * Database: ChromaDB
- </Tip>
- ### LLM
- #### Choosing an LLM
- The following LLM providers are supported by Embedchain:
- - OPENAI
- - ANTHPROPIC
- - VERTEX_AI
- - GPT4ALL
- - AZURE_OPENAI
- - LLAMA2
- - JINA
- - COHERE
- You can choose one by importing it from `embedchain.llm`. E.g.:
- ```python
- from embedchain import App
- from embedchain.llm.llama2 import Llama2Llm
- app = App(llm=Llama2Llm())
- ```
- #### Configuration
- The LLMs can be configured by passing an LlmConfig object.
- The config options can be found [here](/advanced/query_configuration#llmconfig)
- ```python
- from embedchain import App
- from embedchain.llm.llama2 import Llama2Llm
- from embedchain.config import LlmConfig
- app = App(llm=Llama2Llm(), llm_config=LlmConfig(number_documents=3, temperature=0))
- ```
- ### Embedder
- #### Choosing an Embedder
- The following providers for embedding functions are supported by Embedchain:
- - OPENAI
- - HUGGING_FACE
- - VERTEX_AI
- - GPT4ALL
- - AZURE_OPENAI
- You can choose one by importing it from `embedchain.embedder`. E.g.:
- ```python
- from embedchain import App
- from embedchain.embedder.vertexai import VertexAiEmbedder
- app = App(embedder=VertexAiEmbedder())
- ```
- #### Configuration
- The LLMs can be configured by passing an EmbedderConfig object.
- ```python
- from embedchain import App
- from embedchain.embedder.openai import OpenAiEmbedder
- from embedchain.config import EmbedderConfig
- app = App(embedder=OpenAiEmbedder(), embedder_config=EmbedderConfig(model="text-embedding-ada-002"))
- ```
- <Tip>
- You can also pass an `LlmConfig` instance directly to the `query` or `chat` method.
- This creates a temporary config for that request alone, so you could, for example, use a different model (from the same provider) or get more context documents for a specific query.
- </Tip>
- ### Vector Database
- #### Choosing a Vector Database
- The following vector databases are supported by Embedchain:
- - ChromaDB
- - Elasticsearch
- You can choose one by importing it from `embedchain.vectordb`. E.g.:
- ```python
- from embedchain import App
- from embedchain.vectordb.elasticsearch import ElasticsearchDB
- app = App(db=ElasticsearchDB())
- ```
- #### Configuration
- The vector databases can be configured by passing a specific config object.
- These vary greatly between the different vector databases.
- ```python
- from embedchain import App
- from embedchain.vectordb.elasticsearch import ElasticsearchDB
- from embedchain.config import ElasticsearchDBConfig
- app = App(db=ElasticsearchDB(), db_config=ElasticsearchDBConfig())
- ```
- ### PersonApp
- ```python
- from embedchain import PersonApp
- naval_chat_bot = PersonApp("name_of_person_or_character") #Like "Yoda"
- ```
- - `PersonApp` uses OpenAI's model, so these are paid models. 💸 You will be charged for embedding model usage and LLM usage.
- - `PersonApp` uses OpenAI's embedding model to create embeddings for chunks and ChatGPT API as LLM to get answer given the relevant docs. Make sure that you have an OpenAI account and an API key. If you don't have an API key, you can create one by visiting [this link](https://platform.openai.com/account/api-keys).
- - Once you have the API key, set it in an environment variable called `OPENAI_API_KEY`
- ```python
- import os
- os.environ["OPENAI_API_KEY"] = "sk-xxxx"
- ```
- ### Full Configuration Examples
- Embedchain previously offered fully configured classes, namely `App`, `OpenSourceApp`, `CustomApp` and `Llama2App`.
- We deprecated these apps. The reason for this decision was that it was hard to switch from to a different LLM, embedder or vector db, if you one day decided that that's what you want to do.
- The new app allows drop-in replacements, such as changing `App(llm=OpenAiLlm())` to `App(llm=Llama2Llm())`.
- To make the switch to our new, fully configurable app easier, we provide you with full examples for what the old classes would look like implemented as a new app.
- You can swap these in, and if you decide you want to try a different model one day, you don't have to rewrite your whole bot.
- #### App
- App without any configuration is still using the best options available, so you can keep using:
- ```python
- from embedchain import App
- app = App()
- ```
- #### OpenSourceApp
- Use this snippet to run an open source app.
- ```python
- from embedchain import App
- from embedchain.llm.gpt4all import GPT4ALLLlm
- from embedchain.embedder.gpt4all import GPT4AllEmbedder
- from embedchain.vectordb.chroma import ChromaDB
- app = App(llm=GPT4ALLLlm(), embedder=GPT4AllEmbedder(), db=ChromaDB())
- ```
- #### Llama2App
- ```python
- from embedchain import App
- from embedchain.llm.llama2 import Llama2Llm
- app = App(llm=Llama2Llm())
- ```
- #### CustomApp
- Every app is a custom app now.
- If you were previously using a `CustomApp`, you can now just change it to `App`.
- Here's one example, what you could do if we combined everything shown on this page.
- ```python
- from embedchain import App
- from embedchain.config import ElasticsearchDBConfig, EmbedderConfig, LlmConfig
- from embedchain.embedder.openai import OpenAiEmbedder
- from embedchain.llm.llama2 import Llama2Llm
- from embedchain.vectordb.elasticsearch import ElasticsearchDB
- app = App(
- llm=Llama2Llm(),
- llm_config=LlmConfig(number_documents=3, temperature=0),
- embedder=OpenAiEmbedder(),
- embedder_config=EmbedderConfig(model="text-embedding-ada-002"),
- db=ElasticsearchDB(),
- db_config=ElasticsearchDBConfig(),
- )
- ```
- ### Compatibility with other apps
- - If there is any other app instance in your script or app, you can change the import as
- ```python
- from embedchain import App as EmbedChainApp
- from embedchain import PersonApp as EmbedChainPersonApp
- # or
- from embedchain import App as ECApp
- from embedchain import PersonApp as ECPApp
- ```
|