题意:本地运行 llama-index
、uncharted
以及 llama2:7b
来生成索引
问题背景:
I wanted to use llama-index locally with ollama and llama3:8b to index utf-8 json file. I dont have a gpu. I use uncharted to convert docs into json. Now If it is not possible to use llama-index locally without GPU I wanted to use hugging face inference API. But I am not certain if it is free. Can anyone suggest a way?
This is my python code:
from llama_index.core import Document, SimpleDirectoryReader, VectorStoreIndexfrom llama_index.llms.ollama import Ollamaimport jsonfrom llama_index.core import Settings# Convert the JSON document into LlamaIndex Document objectswith open('data/UBER_2019.json', 'r',encoding='utf-8') as f:json_doc = json.load(f)documents = [Document(text=str(doc)) for doc in json_doc]# Initialize Ollama with the local LLMollama_llm = Ollama(model="llama3:8b")Settings.llm = ollama_llm# Create the index using the local LLMindex = VectorStoreIndex.from_documents(documents)#, llm=ollama_llm)
But i keep getting error that there is no OPENAI key. I wanted to use llama2 so that i dont require OPENAI key
Can anyone suggest what i am doing wrong? Also can i use huggingfaceinference API to do indexing of a local json file for free?
问题解决:
You are not setting the embedding model, so I think Llama Index is defaulting to OpenAI.
You must specify an embedding model that does not require an API key.
You can use Ollama:
from llama_index.embeddings.ollama import OllamaEmbedding# Using Nomic
Settings.embed_model = OllamaEmbedding(model_name="nomic-embed-text")# Using Llama
Settings.embed_model = OllamaEmbedding(model_name="llama2")
But there are many options in the documentation like this, this, this