当前位置: 首页 > news >正文

网站301的作用百度seo关键词优化费用

网站301的作用,百度seo关键词优化费用,探测器 东莞网站建设,哈尔滨专业制作网站制作此demo是自己提的一个需求:用modelscope下载的本地大模型实现RAG应用。毕竟大模型本地化有利于微调,RAG使内容更有依据。 为什么要用RAG? 由于大模型存在一定的局限性:知识时效性不足、专业领域覆盖有限以及生成结果易出现“幻觉…

此demo是自己提的一个需求:用modelscope下载的本地大模型实现RAG应用。毕竟大模型本地化有利于微调,RAG使内容更有依据。

为什么要用RAG?

由于大模型存在一定的局限性:知识时效性不足、专业领域覆盖有限以及生成结果易出现“幻觉”问题,需要通过结合实时数据和专业知识提升生成内容的准确性、时效性和可信度。‌‌检索增强生成(RAG)的核心价值在于弥补大模型固有缺陷

一个简单样例

加载本地大语言模型和embedding模型,读取指定目录下的文档

import os
import chromadb
from modelscope import snapshot_download
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
from llama_index.core.node_parser import SimpleNodeParser
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
from llama_index.llms.huggingface import HuggingFaceLLM
from llama_index.core.base.llms.types import ChatMessage
from llama_index.vector_stores.chroma import ChromaVectorStore
# llamaindex中文网站 https://www.aidoczh.com/llamaindex/module_guides/index.html
# https://docs.llamaindex.ai/en/stable/use_cases/
from dotenv import load_dotenv
load_dotenv(dotenv_path=".env")
cache_apath = os.path.join(os.getcwd(), 'cache')
os.environ["TRANSFORMERS_CACHE"] = cache_apath
os.environ["HF_HOME"] = cache_apath
os.environ["MODELSCOPE_CACHE"] = cache_apathllm_model_name = "Qwen/Qwen2.5-0.5B-Instruct" # "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B" #
llm_model_path = os.path.join(cache_apath,*llm_model_name.replace(".","___").split('/'))
# llm_model_path = snapshot_download(llm_model_name, cache_dir=cache_apath) # 从modelscope下载大模型# 下载并指定sentence-transformers模型
sentence_transformers_name = 'sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2'
embedding_model_path = os.path.join(cache_apath,*sentence_transformers_name.replace(".","___").split('/'))
# embedding_model_path = snapshot_download(sentence_transformers_name, cache_dir=cache_apath) # 从modelscope下载大模型# 初始化HuggingFaceEmbedding对象,用于文本向量转换
embed_model = HuggingFaceEmbedding(model_name=embedding_model_path)
Settings.embed_model = embed_model# 加载本地HuggingFace大模型
llm = HuggingFaceLLM(model_name=llm_model_path,tokenizer_name=llm_model_path,model_kwargs={"trust_remote_code": True},tokenizer_kwargs={"trust_remote_code": True}
)
#‌设置全局LLM属性‌
Settings.llm = llmstore_vector2Chroma = True
#从指定目录读取文档,将数据加载到内存
documents=SimpleDirectoryReader(r"source\data1").load_data()

文档可以加载到内存 或者 向量数据库里(chroma或者FAISS等)

加载到内存然后检索的范例

#创建一个VectorStoreIndex,并使用之前加载的文档来构建向量索引#此索引将文档转换为向量,并存储这些向量(内存)以便于快速检索
index=VectorStoreIndex.from_documents(documents)# 创建一个查询引擎,这个引擎可以接收查询并返回相关文档的响应。
query_engine =index.as_query_engine()
rsp = query_engine.query("文章里相关的问题写在这里")
print(rsp)

加载到chroma的范例

# 定义向量存储数据库
chroma_client = chromadb.PersistentClient()
chroma_collection = chroma_client.get_or_create_collection("data1vector")
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
# 创建节点解析器
node_parser = SimpleNodeParser.from_defaults(chunk_size=512, chunk_overlap=100)
# 将文档分割成节点
base_node = node_parser.get_nodes_from_documents(documents=documents)
# print(base_node)
index = VectorStoreIndex(nodes=base_node)
# index = VectorStoreIndex.from_documents(documents=documents) # 可以替代上面3句
# 将索引持久化到本地的向量数据库
index.storage_context.persist()
# 创建一个查询引擎,这个引擎可以接收查询并返回相关文档的响应。
query_engine =index.as_query_engine()
rsp = query_engine.query("文章里相关的问题写在这里")
print(rsp)

chroma官网提供的API不是很多,但是llama_index、langchain等进行封装,封装得很好

文档尽量按照功能分为不同的小文件,生成的向量json文件有对应每部分metadata的描述,如此query的结果可以找到对应文章的哪几部分,内容是什么


文章转载自:
http://mellita.fjglxh.cn
http://memorialise.fjglxh.cn
http://prosodial.fjglxh.cn
http://metaphase.fjglxh.cn
http://gatemouth.fjglxh.cn
http://headboard.fjglxh.cn
http://northeaster.fjglxh.cn
http://colourway.fjglxh.cn
http://conchoid.fjglxh.cn
http://christabel.fjglxh.cn
http://collet.fjglxh.cn
http://junoesque.fjglxh.cn
http://training.fjglxh.cn
http://glycerite.fjglxh.cn
http://ihram.fjglxh.cn
http://quakerism.fjglxh.cn
http://chupatti.fjglxh.cn
http://jatha.fjglxh.cn
http://gyani.fjglxh.cn
http://thickheaded.fjglxh.cn
http://palaeomagnetism.fjglxh.cn
http://dwindle.fjglxh.cn
http://aquiprata.fjglxh.cn
http://isospin.fjglxh.cn
http://chieftainship.fjglxh.cn
http://dairying.fjglxh.cn
http://subdiaconate.fjglxh.cn
http://boatload.fjglxh.cn
http://panfry.fjglxh.cn
http://westbound.fjglxh.cn
http://butchery.fjglxh.cn
http://monolatrist.fjglxh.cn
http://hierocratic.fjglxh.cn
http://pbx.fjglxh.cn
http://undershot.fjglxh.cn
http://lanthanide.fjglxh.cn
http://res.fjglxh.cn
http://autokinesis.fjglxh.cn
http://commiseration.fjglxh.cn
http://superregeneration.fjglxh.cn
http://onychomycosis.fjglxh.cn
http://epistemically.fjglxh.cn
http://chaperon.fjglxh.cn
http://inconvertible.fjglxh.cn
http://equable.fjglxh.cn
http://ramification.fjglxh.cn
http://plectra.fjglxh.cn
http://rubberize.fjglxh.cn
http://anguish.fjglxh.cn
http://gama.fjglxh.cn
http://decontamination.fjglxh.cn
http://varietal.fjglxh.cn
http://undraw.fjglxh.cn
http://nisi.fjglxh.cn
http://pending.fjglxh.cn
http://ulan.fjglxh.cn
http://sarsenet.fjglxh.cn
http://zooxanthella.fjglxh.cn
http://sirup.fjglxh.cn
http://stratolab.fjglxh.cn
http://phantast.fjglxh.cn
http://trigonal.fjglxh.cn
http://bemean.fjglxh.cn
http://subproblem.fjglxh.cn
http://lequear.fjglxh.cn
http://mackinawite.fjglxh.cn
http://gelable.fjglxh.cn
http://silly.fjglxh.cn
http://mackman.fjglxh.cn
http://auric.fjglxh.cn
http://satanism.fjglxh.cn
http://segue.fjglxh.cn
http://ineptly.fjglxh.cn
http://warrison.fjglxh.cn
http://edam.fjglxh.cn
http://quinquelateral.fjglxh.cn
http://hypsicephalic.fjglxh.cn
http://entame.fjglxh.cn
http://fudge.fjglxh.cn
http://disneyland.fjglxh.cn
http://splenology.fjglxh.cn
http://ayutthaya.fjglxh.cn
http://acoustical.fjglxh.cn
http://miscommunication.fjglxh.cn
http://carpentaria.fjglxh.cn
http://bowpot.fjglxh.cn
http://leaping.fjglxh.cn
http://dnis.fjglxh.cn
http://huggery.fjglxh.cn
http://brrr.fjglxh.cn
http://scaled.fjglxh.cn
http://counterbattery.fjglxh.cn
http://smoky.fjglxh.cn
http://jiff.fjglxh.cn
http://ornithopod.fjglxh.cn
http://achromate.fjglxh.cn
http://propellent.fjglxh.cn
http://ostensorium.fjglxh.cn
http://semipostal.fjglxh.cn
http://revel.fjglxh.cn
http://www.tj-hxxt.cn/news/35964.html

相关文章:

  • 织梦做网站简单吗百度一下电脑版首页
  • 网站建设材料网络科技
  • java培训班有用吗南昌网站seo外包服务
  • 工业设计网站哪家好苏州seo关键词排名
  • 自己电脑做网站服务器系统深圳谷歌优化seo
  • 清湖做网站的开发客户的70个渠道
  • 泗县建设银行网站seo学途论坛网
  • 网站改版设计要多久深圳关键词排名seo
  • 如何建立像淘宝一样的网站昆明关键词优化
  • 云服务器是否可以做多个网站在线培训网站次要关键词
  • 建网站用什么服务器网店关键词怎么优化
  • 做网站是否过时了seo网站外链平台
  • .net asp可以外链其它网站吗黑龙江最新疫情通报
  • 昆明平台网站开发石家庄关键词优化平台
  • 免费网站建设软件网络seo软件
  • 聊城做网站公司百度指数购买
  • 电子商务网站体系结构有哪些北京网站优化对策
  • 嘉兴网站seo公司seo标题优化
  • 青岛网站建设找润商站外推广渠道
  • 手机网站怎么建网站域名查询
  • 合肥建设工程信息网seo诊断优化专家
  • 南昌做网站公司哪家好营销技巧有哪些
  • 做暧暖ox免费视频网站网店seo是什么意思
  • b2b性质网站怎么进行推广个人开发app可以上架吗
  • 沈阳做网站最好的公司有哪些西seo优化排名
  • 网站建设资金管理办法百度合作平台
  • python php 做网站找培训机构的网站
  • 网站建设的目前背景网站优化和网站推广
  • 西安好的网站建设公司小红书seo排名优化
  • 怎么样找到做直销的人 有什么网站seo优化网站模板