----------------------
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:
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.
query_engine = index.as_query_engine()
response = query_engine.query("query string")
You can find more details in the
LlamaIndex documentation ().