Closed sherwin684 closed 6 months ago
Hey there, @sherwin684! Great to see you diving deep again with LlamaIndex. Hope you've been well! 🦙✨
Thank you for reporting this issue. It seems like you're encountering a ValueError
when trying to use a local language model and a local embedding model with the as_query_engine
method of the VectorStoreIndex
class. This error is raised because the LlamaIndex Query Engine is designed to interact with OpenAI's API for generating completions, chat responses, and streaming completions. These operations inherently depend on OpenAI's services, which require authentication via an API key.
However, based on the context provided, there are a few potential solutions that have been suggested in similar issues:
embed_model
specified and llm
set to None
. This should allow the use of a local model without requiring an OpenAI API key. Here's the code snippet for reference:index.storage_context.persist(persist_dir="./storage")
loaded_index = load_index_from_storage(StorageContext.from_defaults(persist_dir="./storage"), embed_model=embed_model, llm=None)
(Source: Issue #10051)
OPENAI_API_KEY
environment variable before importing the VectorStoreIndex
. You can do this by adding the following line to your Python script before any imports:import os
os.environ["OPENAI_API_KEY"] = 'your-api-key'
Make sure to replace 'your-api-key'
with your actual OpenAI API key.
(Source: Issue #11900)
llm=None
when creating the ServiceContext
to disable the Language Model (LLM) entirely if you are not intending to use OpenAI's models. Here's the code snippet for reference:service_context = ServiceContext.from_defaults(
chunk_size=2048,
llm=None,
embed_model=embed_model
)
And when you load the index, pass in the service context:
index = load_index_from_storage(storage_context, service_context=service_context)
(Source: Issue #10330)
Please try these solutions and let us know if any of them resolve your issue. If not, we'll continue to investigate and find a solution for you.
@sherwin684 you aren't passing in the embed model to the initial index creation
I would just do this
from llama_index.core.llms import MockLLM
index = VectorStoreIndex.from_documents(documents=documents, embed_model=embed_model)
query_engine = index.as_query_engine(llm=MockLLM())
Yes it worked thanks. It would be great if it is documented as mentioend above. I never found about MockLLM in the documentation regarding using local embedding models.
@logan-markewich if I'm using Azure and not OpenAI directly, do I pass AzureOpenAI
as llm
?
@namedgraph yup 👍 (assuming AzureOpenAI was imported from llama-index of course)
llm=MockLLM()
This worked for me too. Thanks
Bug Description
I am trying to create a query_engine as follows :
And I have used a custom HuggingFaceEmbedding model.
But I get an
ValueError
error when running, saying that I have to specify an Open AI API Key eventhough I am using a local llm and a local embedding model.As mentioned in previous issues https://github.com/run-llama/llama_index/issues/852, a ServiceContext cannot be specified as it it has been deprecated in the current version of llama_index.
Version
llama-index==0.10.20
Steps to Reproduce
Define a local HuggingFaceEmbedding class and specify the index and query engine as follows :
An error arises from the line
Relevant Logs/Tracbacks