llama_index [Bug]:使用AI搜索+llama-index查询构建和检索数据时出现错误,

iyr7buue  于 2个月前  发布在  其他
关注(0)|答案(7)|浏览(31)

根据您提供的错误信息,问题可能出在查询时没有正确地将文本转换为向量。在使用AzureOpenAI和AzureOpenAIEmbedding时,您需要确保在查询之前将文本转换为向量。以下是一个简单的示例,说明如何使用AzureOpenAIEmbedding将文本转换为向量:

from azure.ai.textanalytics import TextAnalyticsClient
from azure.ai.textanalytics.models import (
    CATEGORICAL_DISTRIBUTION,
    DetectedLanguage,
    EntitiesResult,
    KeywordsResult,
    SentenceSentiment,
)
from azure.core.credentials import AzureKeyCredential

# 替换为您的API密钥和终结点

api_key = "your_api_key"
endpoint = "your_endpoint"

# 创建Text Analytics客户端

credential = AzureKeyCredential(api_key)
client = TextAnalyticsClient(endpoint, credential=credential)

# 将文本转换为向量

def text_to_vector(text):
    document = {"id": "1", "language": "en", "text": text}
    response = client.analyze_sentiment(document=document)[0]
    return response.scores[0].value if response.scores else None

# 示例文本

text = "这是一个示例文本。"
vector = text_to_vector(text)
print("文本向量:", vector)

请确保您已正确部署了AzureOpenAIEmbedding模型,并将其与您的API密钥和终结点一起使用。然后,您可以使用text_to_vector函数将查询文本转换为向量,并将其用于搜索索引。

46qrfjad

46qrfjad1#

  • 🤖*

嘿,Gianlucq!很高兴看到你回来。😄我正在处理你的问题,很快就会回来给你一些答案。耐心等待!🚀

wbgh16ku

wbgh16ku2#

  • 🤖*

根据您提供的信息,似乎您正在尝试在查询中使用LlamaIndex的过滤器。然而,当前FaissVectorStore在LlamaIndex中的实现并不支持元数据过滤器。这可以从FaissVectorStore类中的query方法中看出,如果query.filters不是None,它会引发ValueError。以下是相关的代码片段:

def query(
    self,
    query: VectorStoreQuery,
    **kwargs: Any,
) -> VectorStoreQueryResult:
    """Query index for top k most similar nodes.

Args:
query_embedding (List[float]): query embedding
similarity_top_k (int): top k most similar nodes

"""
    if query.filters is not None:
        raise ValueError("Metadata filters not implemented for Faiss yet.")

这意味着,如果您尝试在查询中使用过滤器,它将无法按预期工作并引发错误。
关于可过滤的元数据(作者、主题和导演)始终为空的问题,可能是因为FaissVectorStore没有存储任何文本或元数据。这可以通过stores_text属性设置为False以及add方法中的注解来指示:

class FaissVectorStore(BasePydanticVectorStore):
    """Faiss Vector Store.

Embeddings are stored within a Faiss index.

During query time, the index uses Faiss to query for the top
k embeddings, and returns the corresponding indices.

Args:
faiss_index (faiss.Index): Faiss index instance

"""

    stores_text: bool = False
def add(
    self,
    nodes: List[BaseNode],
    **add_kwargs: Any,
) -> List[str]:
    """Add nodes to index.

NOTE: in the Faiss vector store, we do not store text in Faiss.

Args:
nodes: List[BaseNode]: list of nodes with embeddings

"""

这意味着与节点相关联的任何文本或元数据都没有存储在Faiss索引中,因此无法检索。
您可以在llama_index/vector_stores/faiss.py文件中找到这些详细信息。
至于AI搜索索引,LlamaIndex通过OpenAIEmbedding类支持它。此类使用OpenAI的API为文本数据生成嵌入。这些嵌入可用于各种任务,包括文本搜索。您可以在llama_index/embeddings/openai.py文件中找到有关此的更多详细信息。
我希望这能帮助您解决遇到的问题。如果您有任何其他问题或需要进一步澄清,请随时提问。

参考资料

此响应旨在节省您的时间并提供帮助。它不是精确的解决方案,而是您自己研究的起点。
请帮助我变得更有用!如果这有帮助请留下一个👍,如果无关请留下一个👎。
如果您想继续对话,请以@dosu-bot开始回复。

tjvv9vkg

tjvv9vkg3#

我正在尝试复制您文档中提供的关于将AI Search用作向量索引存储的示例。我没有使用FaissVectorStore!!!
以下是链接的引用:https://docs.llamaindex.ai/en/stable/examples/vector_stores/CognitiveSearchIndexDemo.html
但是它不起作用!
如何解决这个问题?

hivapdat

hivapdat4#

有人能帮我制作一个带有认知搜索的llama-index示例吗?谢谢。

ie3xauqp

ie3xauqp5#

我无法访问Azure来测试这个。但我知道Azure团队正在努力更新这个集成,希望很快能实现 :)

g52tjvyc

g52tjvyc6#

你好,@Gianlucq

我正在帮助LlamaIndex团队管理他们的待办事项,并将此问题标记为过时。看起来你在使用AI搜索和llama-index构建和查询数据时遇到了问题,特别是在对向量进行查询时,注意到可过滤的元数据字段总是为空。我已经提供了详细的回复,解释了当前实现的局限性,另一个用户logan-markewich提到Azure团队正在更新集成。

请问这个问题是否仍然与LlamaIndex仓库的最新版本相关?如果是,请通过评论告知LlamaIndex团队。否则,请随意关闭该问题,或者它将在7天后自动关闭。

感谢您的理解和合作。如果您有任何进一步的问题或需要协助,请随时联系。

smtd7mpg

smtd7mpg7#

你好!我确认这个问题仍然与LlamaIndex存储库的最新版本相关。作为解决方法,我从原始版本创建了一个自定义类,并更改了特定方法以启用使用标志使字段可过滤或不可过滤的功能!

问候
通过iOS发送的Outlook< https://aka.ms/o0ukef >...

相关问题