llama-index,uncharted and llama2:7b run locally to generate Index

题意:本地运行 llama-indexuncharted 以及 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, VectorStoreIndex
    from llama_index.llms.ollama import Ollama
    import json
    from llama_index.core import Settings
    
    
    # Convert the JSON document into LlamaIndex Document objects
    with 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 LLM
    ollama_llm = Ollama(model="llama3:8b")
    Settings.llm = ollama_llm
    
    # Create the index using the local LLM
    index = 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 thisthisthis

相关推荐

  1. llama-recipes

    2024-07-18 04:10:02       24 阅读
  2. LlaMa 2

    2024-07-18 04:10:02       23 阅读
  3. Llama - Prompting

    2024-07-18 04:10:02       20 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-18 04:10:02       66 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-18 04:10:02       70 阅读
  3. 在Django里面运行非项目文件

    2024-07-18 04:10:02       57 阅读
  4. Python语言-面向对象

    2024-07-18 04:10:02       68 阅读

热门阅读

  1. 从入门到高手的99个python案例

    2024-07-18 04:10:02       18 阅读
  2. Springboot Excel 导出工具 -- EasyPoi 简介

    2024-07-18 04:10:02       22 阅读
  3. 智能家居的优缺点有哪些?

    2024-07-18 04:10:02       17 阅读
  4. RedisServer解析(一)

    2024-07-18 04:10:02       24 阅读
  5. 【算法模板】数论:杨辉三角求组合数

    2024-07-18 04:10:02       23 阅读
  6. 【算法】位运算

    2024-07-18 04:10:02       21 阅读