Find answers from the community

Updated 11 months ago

how to set 2 different models , onde for

how to set 2 different models , onde for LLM AZURE and OTHER from OPENAI for embedding
V
k
4 comments
@kapa.ai how to use different models for LLM and embedding?
Let me check the knowledge base for you. One moment! :books:
----------------------
In LlamaIndex, you can use different models for LLM and embedding. Here's how you can do it:

For LLMs, you can interact with them in a few primary ways as mentioned in the LlamaIndex documentation (). However, the specific code or steps to use different LLMs are not provided in the extracts.

For embeddings, the most common usage for an embedding model will be setting it in the service context object, and then using it to construct an index and query. The input documents will be broken into nodes, and the embedding model will generate an embedding for each node. By default, LlamaIndex will use text-embedding-ada-002. Here's an example of how to set it up:

Plain Text
from llama_index import ServiceContext, VectorStoreIndex, SimpleDirectoryReader
from llama_index.embeddings import OpenAIEmbedding

embed_model = OpenAIEmbedding()
service_context = ServiceContext.from_defaults(embed_model=embed_model)

# Optionally set a global service context to avoid passing it into other objects every time
from llama_index import set_global_service_context

set_global_service_context(service_context)

documents = SimpleDirectoryReader("./data").load_data()

index = VectorStoreIndex.from_documents(documents)


Then, at query time, the embedding model will be used again to embed the query text.

Plain Text
query_engine = index.as_query_engine()

response = query_engine.query("query string")


You can find more details in the LlamaIndex documentation ().
Please note that if you change your embedding model, you must re-index your data. Furthermore, you should ensure the same embedding model is used for both indexing and querying.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord