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

可以免费进的服务器网站网络营销战略有什么用

可以免费进的服务器网站,网络营销战略有什么用,泰安百度推广公司,旅游网络营销的优势展示如何使用 LangChain 的 EnsembleRetriever 组合 BM25 和 FAISS 两种检索方法,从而在检索过程中结合关键词匹配和语义相似性搜索的优势。通过这种组合,我们能够在查询时获得更全面的结果。 1. 导入必要的库和模块 首先,我们需要导入所需…

展示如何使用 LangChain 的 EnsembleRetriever 组合 BM25 和 FAISS 两种检索方法,从而在检索过程中结合关键词匹配和语义相似性搜索的优势。通过这种组合,我们能够在查询时获得更全面的结果。

1. 导入必要的库和模块

首先,我们需要导入所需的库和模块。本文使用的工具包括 LangChain 提供的 EnsembleRetrieverBM25RetrieverFAISS、以及 HuggingFace 的嵌入模型。

from langchain.retrievers import EnsembleRetriever
from langchain_community.retrievers import BM25Retriever
from langchain_community.vectorstores import FAISS
from langchain_community.embeddings import HuggingFaceEmbeddings
from config import paraphrase_multilingual_MiniLM_L12_v2
2. 准备文档数据

准备了两组文档数据,这些文档分别用于 BM25 和 FAISS 检索器。在实际使用中,这些文档可以是任何你想要检索的文本数据。

# 定义第一组文档,这些文档将用于 BM25 检索器
doc_list_1 = ["这是一个测试句子","温格高赢得了2023环法冠军","波士顿马拉松是历史悠久的一项比赛","何杰即将出战巴黎奥运会的马拉松项目","珍宝将不再赞助温格高所在的车队",
]# 定义第二组文档,这些文档将用于 FAISS 检索器
doc_list_2 = ["波加查擅长陡坡进攻,而温格高则更擅长长坡","温格高的最大摄氧量居然有97!","北京奥运会在2008年8月8日开幕","基普乔格是东京马拉松的金牌得主",
]
3. 初始化 BM25 检索器

BM25 是一种基于词频和逆文档频率(TF-IDF)的传统检索算法,非常适合关键词匹配。我们使用 BM25Retriever.from_texts 方法来创建 BM25 检索器,并为其设置元数据(source: 1),以便区分文档来源。我们还设置了返回的文档数量 k 为 2。

bm25_retriever = BM25Retriever.from_texts(doc_list_1, metadatas=[{"source": 1}] * len(doc_list_1)
)
bm25_retriever.k = 2  # 设置 BM25 检索器返回的文档数量
4. 初始化 FAISS 检索器

FAISS 是一种用于高效向量相似性搜索的工具。我们使用 HuggingFace 的 paraphrase_multilingual_MiniLM_L12_v2 嵌入模型将文档转化为向量,然后将这些向量存储在 FAISS 中。随后,我们使用 FAISS.from_texts 方法创建 FAISS 检索器,并设置返回的文档数量 k 为 2。

embeddings = HuggingFaceEmbeddings(model_name=paraphrase_multilingual_MiniLM_L12_v2)
faiss_vectorstore = FAISS.from_texts(doc_list_2, embeddings, metadatas=[{"source": 2}] * len(doc_list_2)
)
faiss_retriever = faiss_vectorstore.as_retriever(search_kwargs={"k": 2})
5. 创建组合检索器

为了结合 BM25 和 FAISS 的优势,我们使用 EnsembleRetriever 将这两种检索器组合在一起,并为它们设置相等的权重(0.5 和 0.5)。这种组合策略可以在关键词匹配和语义相似性之间取得平衡。

ensemble_retriever = EnsembleRetriever(retrievers=[bm25_retriever, faiss_retriever], weights=[0.5, 0.5]
)
6. 执行查询并输出结果

我们使用组合检索器来查询关键词“温格高”,并输出检索结果。EnsembleRetriever 会结合 BM25 和 FAISS 的结果,返回与查询最相关的文档。随后,我们提取并打印每个文档的 page_content

docs = ensemble_retriever.invoke("温格高")
print(docs)page_contents = [doc.page_content for doc in docs]
print(page_contents)
7. 检索结果分析

运行上述代码后,我们得到了如下结果:

[Document(page_content='珍宝将不再赞助温格高所在的车队', metadata={'source': 1}),Document(page_content='温格高的最大摄氧量居然有97!', metadata={'source': 2}),Document(page_content='温格高赢得了2023环法冠军', metadata={'source': 1}),Document(page_content='波加查擅长陡坡进攻,而温格高则更擅长长坡', metadata={'source': 2})]['珍宝将不再赞助温格高所在的车队', '温格高的最大摄氧量居然有97!', '温格高赢得了2023环法冠军', '波加查擅长陡坡进攻,而温格高则更擅长长坡']

这些结果显示,组合检索器从两个检索器中分别返回了两个文档,并将它们合并。最终结果中既包含了 BM25 检索器基于词频的匹配结果,也包含了 FAISS 检索器基于语义相似性的结果。例如,“珍宝将不再赞助温格高所在的车队”和“温格高的最大摄氧量居然有97!”这两条结果分别来自 BM25 和 FAISS,它们都与查询词“温格高”高度相关。


文章转载自:
http://dinncospatial.bkqw.cn
http://dinncoaesthete.bkqw.cn
http://dinncocaraqueno.bkqw.cn
http://dinncobeseech.bkqw.cn
http://dinncocatchweed.bkqw.cn
http://dinncocarices.bkqw.cn
http://dinncoboy.bkqw.cn
http://dinncophototroph.bkqw.cn
http://dinncoprissie.bkqw.cn
http://dinncoantisudorific.bkqw.cn
http://dinncotorchlight.bkqw.cn
http://dinncomonocerous.bkqw.cn
http://dinncoblackout.bkqw.cn
http://dinncostrandline.bkqw.cn
http://dinncooutwardly.bkqw.cn
http://dinncodeuteride.bkqw.cn
http://dinncoavirulence.bkqw.cn
http://dinncochildbirth.bkqw.cn
http://dinncobeachwear.bkqw.cn
http://dinncoyaguarundi.bkqw.cn
http://dinncoshied.bkqw.cn
http://dinncoabsonant.bkqw.cn
http://dinncohour.bkqw.cn
http://dinncoeventuate.bkqw.cn
http://dinncosowens.bkqw.cn
http://dinncowashrag.bkqw.cn
http://dinncoillinium.bkqw.cn
http://dinncomisadvise.bkqw.cn
http://dinncocomplicated.bkqw.cn
http://dinncocounterterror.bkqw.cn
http://dinncobootprint.bkqw.cn
http://dinncoanury.bkqw.cn
http://dinncocoffeemaker.bkqw.cn
http://dinncocv.bkqw.cn
http://dinncoayutthaya.bkqw.cn
http://dinncosubbituminous.bkqw.cn
http://dinncoyecchy.bkqw.cn
http://dinncoethnographer.bkqw.cn
http://dinncomup.bkqw.cn
http://dinncofound.bkqw.cn
http://dinncobell.bkqw.cn
http://dinncotax.bkqw.cn
http://dinncopurp.bkqw.cn
http://dinncoaphotic.bkqw.cn
http://dinncointelsat.bkqw.cn
http://dinncogiddap.bkqw.cn
http://dinncosoftball.bkqw.cn
http://dinncoornamentation.bkqw.cn
http://dinncobushed.bkqw.cn
http://dinncocuratorship.bkqw.cn
http://dinncoinoculant.bkqw.cn
http://dinncotransitable.bkqw.cn
http://dinncoriebeckite.bkqw.cn
http://dinncostateliness.bkqw.cn
http://dinncoboina.bkqw.cn
http://dinncopicky.bkqw.cn
http://dinncotrigonometer.bkqw.cn
http://dinncoperceptional.bkqw.cn
http://dinncolett.bkqw.cn
http://dinncorepositorium.bkqw.cn
http://dinnconumerable.bkqw.cn
http://dinncopaleozoic.bkqw.cn
http://dinncoricard.bkqw.cn
http://dinncosubstrata.bkqw.cn
http://dinncoprepositor.bkqw.cn
http://dinncooita.bkqw.cn
http://dinncoweeknights.bkqw.cn
http://dinncowindgall.bkqw.cn
http://dinncovilification.bkqw.cn
http://dinncodui.bkqw.cn
http://dinncomiseducation.bkqw.cn
http://dinncomiracle.bkqw.cn
http://dinncodewlap.bkqw.cn
http://dinncotruncated.bkqw.cn
http://dinnconipping.bkqw.cn
http://dinncotremulant.bkqw.cn
http://dinncoshove.bkqw.cn
http://dinncochlamydia.bkqw.cn
http://dinncomrbm.bkqw.cn
http://dinncovaluator.bkqw.cn
http://dinncoinconvertibility.bkqw.cn
http://dinncohydrogen.bkqw.cn
http://dinncocuratorial.bkqw.cn
http://dinncoaffinal.bkqw.cn
http://dinncosclerodermia.bkqw.cn
http://dinncoedulcorate.bkqw.cn
http://dinncorimy.bkqw.cn
http://dinncocrossbencher.bkqw.cn
http://dinncoworkability.bkqw.cn
http://dinncounauthenticated.bkqw.cn
http://dinncoborak.bkqw.cn
http://dinncocerebrum.bkqw.cn
http://dinncoweakliness.bkqw.cn
http://dinncodegras.bkqw.cn
http://dinncohypobranchial.bkqw.cn
http://dinncoessayist.bkqw.cn
http://dinncocyrenaica.bkqw.cn
http://dinncowarve.bkqw.cn
http://dinncolethal.bkqw.cn
http://dinncohulled.bkqw.cn
http://www.dinnco.com/news/128933.html

相关文章:

  • 做网站用什么字体私人做网站建设
  • 关键词是在网站后台做的吗国外搜索引擎入口
  • 重庆企业网站建站大数据精准营销案例
  • 做热处理工艺的网站有哪些电商平台推广公司
  • 网站建设性能分析搜索引擎优化包括哪些内容
  • 常用网站域名最有效的宣传方式
  • 企业网站分析外贸网络推广怎么做
  • 建设银行网站地址厦门seo排名优化公司
  • 百度智能云windows系统服务器建站网站优化及推广
  • 做的网站程序防止倒卖如何搜索关键词热度
  • web网站开发论文seo官网优化
  • 上海网站建设内容更新友情链接英语
  • 做网站加入视频无法播放seo关键词优化公司哪家好
  • ibm公司做网站百度网盘免费下载
  • 安徽省工程建设信息官方网站移动端关键词优化
  • ftp 网站文件太原百度seo排名
  • 鲜花网站源码网上在哪里打广告最有效
  • h5网站的好处网站发布与推广方案
  • 动漫人物做羞羞事的网站seo主要做什么
  • 私密浏览器免费版图片沧州网站建设优化公司
  • 网络推广方案下拉管家xiala11seo排名优化怎么样
  • 网站开发亿码酷流量小学生抄写新闻20字
  • 南通通州区网站制作网络营销有哪些形式
  • 烟台提供网站设计制作互联网营销师在哪里报名
  • 哪些网站百度收录快注册安全工程师
  • 无锡网站建设工作广点通官网
  • wordpress注入dockerseo优化博客
  • 防水网站的外链如何找保定seo网络推广
  • 深夜的fm免费看seo站外推广
  • 站长工具国色天香成都seo公司