llama_index [Bug]: 在运行具有相同索引名称的Elasticsearch时出现查询id错误

jtjikinw  于 22天前  发布在  ElasticSearch
关注(0)|答案(3)|浏览(27)

Bug描述

在运行具有相同索引名称的Elasticsearch时,进入生成响应的查询时出现错误。
查询id 40b9d01f-b211-413d-b3d4-a799eff700d6 在 retriever_dict 或 query_engine_dict 中都未找到。
如何解决这个错误?
我正在采取的一些临时解决方法是:通过更改索引名称来避免错误,那么如何在不更改索引名称的情况下解决错误?

版本

llama-index==0.10.12

重现步骤

from dense_pack2.base import DenseXRetrievalPack as dp2
from llama_index.vector_stores.elasticsearch import ElasticsearchStore
vector_store = ElasticsearchStore(
 index_name="dense_index_56",
 es_url=" [http://localhost:9200](http://localhost:9200) ",
)
  • 无响应*
r1zk6ea1

r1zk6ea11#

要解决Elasticsearch中的错误 "Query id 40b9d01f-b211-413d-b3d4-a799eff700d6 在 retriever_dictquery_engine_dict 中未找到",而无需更改索引名称,您需要确保查询ID在 retriever_dictquery_engine_dict 中正确注册。此错误通常表示系统无法识别查询ID。
以下是一个代码片段,可以帮助您确保 RetrieverQueryEngine 正确设置:

from llama_index.vector_stores.elasticsearch import ElasticsearchStore
from dense_pack2.base import DenseXRetrievalPack as dp2
from llama_index.core import RetrieverQueryEngine, QueryBundle

# Initialize ElasticsearchStore
vector_store = ElasticsearchStore(
    index_name="dense_index_56",
    es_url="http://localhost:9200",
)

# Initialize DenseXRetrievalPack
retriever_chunk = dp2(
    documents,
    proposition_llm=global_variable.embed_model,
    query_llm=global_variable.llm,
    text_splitter=SentenceSplitter(chunk_size=1024),
    vector_store=vector_store
)

# Ensure the retriever and query engine are properly instantiated
retriever = retriever_chunk.retriever
response_synthesizer = retriever_chunk.query_engine.response_synthesizer

# Instantiate the RetrieverQueryEngine
query_engine = RetrieverQueryEngine(
    retriever=retriever,
    response_synthesizer=response_synthesizer
)

# Register the query ID in the appropriate dictionary
query_id = "40b9d01f-b211-413d-b3d4-a799eff700d6"
retriever_dict = {query_id: retriever}
query_engine_dict = {query_id: query_engine}

# Now you can use the query engine to handle queries
query_bundle = QueryBundle(query_str="your query here")
response = query_engine._query(query_bundle)
print(response)

确保将 query_id 正确添加到 retriever_dictquery_engine_dict 中,并确保 RetrieverQueryEngine 用必要的组件正确示例化。这应该可以在不更改索引名称 1(https://github.com/run-llama/llama_index/blob/main/llama-index-legacy/llama_index/legacy/query_engine/retriever_query_engine.py) 的情况下解决错误。

  • 要继续与 Dosu 对话,请提及 @dosu。*
ego6inou

ego6inou2#

LikhithRishi,这个概念验证的llama包并不是完全考虑到了外部矢量存储。
我们需要将all_nodes存储在docstore中(如果我们想稍后重建,需要保存和加载docstore)
对源代码进行快速更改如下(以允许传入矢量存储并将节点存储在docstore中)

self.vector_index = VectorStoreIndex(
            all_nodes, 
            service_context=service_context,
            storage_context=StorageContext.from_defaults(vector_store=vector_store),
            show_progress=True,
            store_nodes_override=True,
        )

当然欢迎贡献,或者你可以下载/编辑代码并在本地运行

wfypjpf4

wfypjpf43#

@LikhithRishi,这个概念验证的llama包并不是专门为外部矢量存储设计的。
我们需要将all_nodes存储在docstore中(如果以后想要重建,需要保存和加载docstore)
对源代码进行快速更改如下(以允许传入矢量存储并将节点存储在docstore中)

self.vector_index = VectorStoreIndex(
            all_nodes, 
            service_context=service_context,
            storage_context=StorageContext.from_defaults(vector_store=vector_store),
            show_progress=True,
            store_nodes_override=True,
        )

当然欢迎大家的贡献,或者你可以下载/编辑代码并在本地运行。

嗨 @logan-markewich ,
我们尝试了这个方法,但它不起作用,以下是我们正在使用的代码行:
`
storage_context = StorageContext.from_defaults(vector_store=vector_store)

self.vector_index = VectorStoreIndex(
        all_nodes, service_context=service_context, show_progress=True, storage_context=storage_context,

store_nodes_override=True
)
`

相关问题