griptape icon indicating copy to clipboard operation
griptape copied to clipboard

VectorQueryEngine issue with loading artifacts from query

Open qwe321389yfs8t7huqd89q opened this issue 1 month ago • 0 comments

Describe the bug Using this example and Redis I'm getting error: Response: error querying vector store: string indices must be integers, not 'str'

[05/14/24 13:22:38] INFO     Subtask 14c519c5ea9747a381ef8aa97f4aa055
                             Response: error querying vector store: string indices must be integers, not 'str'
[05/14/24 13:22:53] INFO     Subtask f787fb764f1e4e9ea70d684662820fb3
                             Thought: The error message indicates a persistent issue with the JSON structure, and my previous
                             corrections have not resolved it. I need to re-evaluate the JSON object I am submitting to ensure it
                             adheres to the schema. I will carefully review the JSON schema for the griptape_tool action and make
                             sure that the structure of my action request is correct.
                             Actions: [{"tag": "griptape_info_search_corrected", "name": "griptape_tool", "path": "search",
                             "input": {"values": {"query": "What is Griptape?"}}}]

I don't have any other Vector DB so not sure if same thing happens with other drivers, looking at source code it should behave same as for Redis.

Tracked it down to this line: https://github.com/griptape-ai/griptape/blob/a899f5af59c6b624d8fca8461bc26c745c8ecb4d/griptape/engines/query/vector_query_engine.py#L36

It assumes that meta is dict, but in fact query returns string from DB.

Possible solutions

  1. Fix it in one place, in VectorQueryEngine (only a quick fix to make example code work with Redis):
[...]
import json
[...]
artifacts = [
            artifact
            for artifact in [BaseArtifact.from_json((r.meta["artifact"] if isinstance(r.meta, dict) else json.loads(r.meta)["artifact"])) for r in result if r.meta]
            if isinstance(artifact, TextArtifact)
        ]
[...]
  1. Modify each Vector Driver so that query returns meta as dict.
  2. Modify VectorQueryEngine to use load_entry method from Vector Driver before loading artifact.

I think best would be second option, as it won't affect LocalVectorStoreDriver.

Desktop (please complete the following information):

  • OS: Win 11
  • Griptape Version 0.25.0

qwe321389yfs8t7huqd89q avatar May 14 '24 12:05 qwe321389yfs8t7huqd89q