haystack 无法连接到AWS OpenSearch Serverless,

brccelvz  于 4个月前  发布在  其他
关注(0)|答案(2)|浏览(52)

描述bug

无法连接到aws opensearch服务器。以下是代码片段。

from haystack_integrations.document_stores.opensearch import OpenSearchDocumentStore
from haystack_integrations.components.embedders.amazon_bedrock import AmazonBedrockTextEmbedder
from requests_aws4auth import AWS4Auth
from opensearchpy import OpenSearch, RequestsHttpConnection
from boto3 import Session
from haystack import Pipeline

service = 'aoss'
credentials = Session().get_credentials()
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key,
                   "us-east-1", service, session_token=credentials.token)

embedder = AmazonBedrockTextEmbedder(model="amazon.titan-embed-text-v1")
docstore = OpenSearchDocumentStore(
    hosts = <opensearch serverless endpoint>,
    index = "jps-test-index",
    http_auth= awsauth,
    timeout=300,
    use_ssl=True,
    verify_certs=True,
    connection_class=RequestsHttpConnection,
    engine = "faiss"
    # return_embedding=True

)
query_pipeline = Pipeline()
query_pipeline.add_component("text_embedder", embedder)
query_pipeline.add_component("retriever", OpenSearchEmbeddingRetriever(document_store=docstore))
query_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")

query = "How many languages are there?"

result = query_pipeline.run({"text_embedder": {"text": query}})

print(result['retriever']['documents'][0])

错误信息

File "/root/bosai/genai/eric-bosaiapps-genai-poc/haystack-demo/venv/lib/python3.10/site-packages/opensearchpy/transport.py", line 416, in perform_request
    status, headers_response, data = connection.perform_request(
  File "/root/bosai/genai/eric-bosaiapps-genai-poc/haystack-demo/venv/lib/python3.10/site-packages/opensearchpy/connection/http_requests.py", line 241, in perform_request
    self._raise_error(
  File "/root/bosai/genai/eric-bosaiapps-genai-poc/haystack-demo/venv/lib/python3.10/site-packages/opensearchpy/connection/base.py", line 315, in _raise_error
    raise HTTP_EXCEPTIONS.get(status_code, TransportError)(
opensearchpy.exceptions.NotFoundError: NotFoundError(404, '')

预期行为

检索文档

其他上下文

在此添加有关问题的其他上下文,例如文档类型/预处理步骤/阅读器设置等。

重现

重现行为所需的步骤

FAQ检查

  • 你查看过 our new FAQ page 吗?
    系统:
  • 操作系统:linux
  • GPU/CPU:cpu
  • Haystack版本(提交或版本号):

amazon-bedrock-haystack 0.9.2
haystack-ai 2.2.4
opensearch-haystack 0.7.1

  • 文档存储:
  • 阅读器:
  • 检索器:
hgc7kmma

hgc7kmma1#

你好@adhikari23,我整理了你的代码发布,以便更好地阅读。
首先,看起来你缺少一个导入:

from haystack_integrations.components.retrievers.opensearch import OpenSearchEmbeddingRetrieve

查看你的错误信息,似乎与你的OpenSearch服务器的连接有问题。你能在隔离状态下连接它吗?即:在haystack之外?

sulc1iza

sulc1iza2#

是的,我能够连接到haystack之外的opensearch服务器。

相关问题