llama_index : VectorStoreIndex

I have the following python codes:

from llama_index import ( SimpleDirectoryReader, VectorStoreIndex, ) documents = SimpleDirectoryReader("docs").load_data() index = VectorStoreIndex.from_documents(documents) #Why is there openAI exception thrown here? Do i need openai for this? I don't like openai API as i don't want to pay for using it. 

Message=No API key found for OpenAI. Please set either the OPENAI_API_KEY environment variable or openai.api_key prior to initialization. API keys can be found or created at

Source=D:\MyGit\testAI\demo1\demo1.py StackTrace: File "D:\MyGit\testAI\demo1\demo1.py", line 14, in (Current frame) index = VectorStoreIndex.from_documents(documents) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: No API key found for OpenAI. Please set either the OPENAI_API_KEY environment variable or openai.api_key prior to initialization. API keys can be found or created at

I have tried the above codes and i don't understand why i need openai key!?

2 Answers

Llama_index is built on OpenAI, it uses various GPT models. You can even specify which ones you want to use.

Llama-index (or in general, RAG) requires two components:

  1. A "retriever" which can communicate with an "index" of embeddings created earlier
  2. A "response synthesizer" which will augment the responses retrieved by the earlier stage and generate a response

For both the tasks, llama-index uses OpenAI by default. You can configure several other large language models for either tasks - for the Embedding Generation / Indexing / Retrieving, as well as for Response Synthesis.

Once you move to HuggingFace / local models for both these tasks, you will no longer encounter the OpenAI error.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like