欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 汽车 > 时评 > How to use Solr as retriever in RAG

How to use Solr as retriever in RAG

2025/6/10 12:19:24 来源:https://blog.csdn.net/suiusoar/article/details/140232720  浏览:    关键词:How to use Solr as retriever in RAG

题意:怎样在 RAG 中使用 Solr 作为检索器

问题背景:

I want to build a RAG (Retrieval Augmented Generation) service with LangChain and for the retriever I want to use Solr. There is already a python package eurelis-langchain-solr-vectorstore where you can use Solr in combination with LangChain but how do I define server credentials? And my embedding model is already running on a server. I thought something like this but I don't know

如果您想使用 LangChain 构建一个 RAG(Retrieval Augmented Generation)服务,并且希望使用 Solr 作为检索器,同时您已经了解到有一个名为 eurelis-langchain-solr-vectorstore 的 Python 包可以将 Solr 与 LangChain 结合使用,那么接下来您需要考虑如何配置 Solr 服务器的凭据以及如何处理您的嵌入模型。

import requests
from eurelis_langchain_solr_vectorstore import Solrembeddings_model = requests.post("http://server-insight/embeddings/")solr = Solr(embeddings_model, core_kwargs={'page_content_field': 'text_t',  # field containing the text content'vector_field': 'vector',        # field containing the embeddings of the text content'core_name': 'langchain',        # core name'url_base': 'http://localhost:8983/solr' # base url to access solr})  # with custom default core configurationretriever = solr.as_retriever()

问题解决:

For the first question: For basic credentials you can send them in the url with the login:password@ pattern

对于第一个问题:对于基本认证信息,您可以在 URL 中使用 login:password@ 模式来发送它们。

http://localhost:8983/solr => http://login:password@localhost:8983/solr

For the second one: to use your embeddings server you need to provide the Solr vector store with a class inheriting from langchain_core.embeddings.embeddings.Embeddings

对于第二种方法:要使用您的嵌入服务器,您需要向 Solr 向量存储提供一个继承自 langchain_core.embeddings.embeddings.Embeddings 的类。

it must then implement both        必须实现以下2者

def embed_documents(self, texts: List[str]) -> List[List[float]]:"""Embed search docs."""

and

def embed_query(self, text: str) -> List[float]:"""Embed query text."""

in both methods you can use your http://server-insight/embeddings/ endpoint.

在两种方法中,您都可以使用 http://server-insight/embeddings/ 这个端点

First method is used at indexing time and is intended to work with a list of text and return a list of embeddings

第一种方法是在索引时使用的,旨在处理一个文本列表并返回一个嵌入列表(每个文本对应的嵌入向量)

second one is used at query time and is intended to work with a single text and return a single embedding (a single list of float)

第二个是在查询时使用的,旨在处理单个文本并返回一个单一的嵌入(一个浮点数列表)。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词