python-django-LlamaIndex 精简版

🚀 一键安装LlamaIndex

pip install llama-index

📁 准备你的数据文件,无论是txt还是pdf,放入data文件夹,一切就绪。

🔧 简单几步,在views.py中集成LlamaIndex,代码如下:

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader

def llamaIndexOpenAiSearch(request):
    documents = SimpleDirectoryReader("data").load_data()
    index = VectorStoreIndex.from_documents(documents)
    response = index.as_query_engine().query("你的查询")
    return JsonResponse({'response': response})

🔗 路由配置,快速接入:

path('llama-index-open-ai-search/', views.llamaIndexOpenAiSearch, name='search'),

💾 索引持久化,存储到磁盘,代码示例:

index.storage_context.persist(persist_dir="你的存储路径")

📈 向量数据库集成,提升检索效率:

from chromadb import PersistentClient
# 省略其他代码...

def searchIndexVectory():
    db = PersistentClient(path="你的数据库路径")
    # 省略其他代码...

🌐 访问http://127.0.0.1:8080/llama-index-open-ai-search,体验快速检索。

🛠️ 根据需求配置本地模型,代码示例:

# 省略其他代码...
embed_model = HuggingFaceEmbedding(model_name="sentence-transformers/all-MiniLM-L6-v2")
llm = HuggingFaceLLM(model_name="gpt2", device_map="cpu")
# 省略其他代码...

相关推荐

  1. python-django-LlamaIndex 精简

    2024-07-10 23:14:03       28 阅读
  2. Python Django

    2024-07-10 23:14:03       53 阅读
  3. 【linux】精简代码备份

    2024-07-10 23:14:03       29 阅读

最近更新

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

    2024-07-10 23:14:03       100 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 23:14:03       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 23:14:03       90 阅读
  4. Python语言-面向对象

    2024-07-10 23:14:03       98 阅读

热门阅读

  1. 深入Django(五)

    2024-07-10 23:14:03       31 阅读
  2. Django之登录权限系统

    2024-07-10 23:14:03       27 阅读
  3. LeetCode 35, 242, 994

    2024-07-10 23:14:03       23 阅读
  4. tcp 中的poll机制介绍

    2024-07-10 23:14:03       26 阅读
  5. python excel openpyxl

    2024-07-10 23:14:03       23 阅读
  6. 生物环保的技术原理和优点是什么

    2024-07-10 23:14:03       25 阅读