Find answers from the community

Updated 3 months ago

Metadata

hi guys, I'm trying to pass a list of entities as metadata along my inserted documents, but I'm getting back an error: Value for metadata entities must be one of (str, int, float, None)
L
v
21 comments
Are you using a vector db integration? Some vector dbs require metadata to be a flat dictionary :PSadge:
Quick fix is casting to a string or similar
I'm using Pinecone, but that suports list of stirngs
Attachment
Screenshot_2023-08-08_at_08.22.54.png
tried converting the list to a set (flat dict) via: set(["entity.."])
which gave back {"entity"} but still getting the error
Sorry, when I said flat dict, I meant to cast the entire list or set as a string. I.e the entire metadata dictionary us being forced to str -> str,int,float
Seems like we need to allow a list of strings for pinecone at some point πŸ€·β€β™‚οΈ
like this? str(entities)
sorry, I'm not excelling in python
especially when it comes to its type system πŸ˜›
No worries, and pretty much

Or if you are just updating an existing metadata dictionary, something like metadata["entities"] = str(metadata["entitites"])
ok, so when I'm inserting along new documents, I do:
Plain Text
entities = ["Tom", "Peter"]
metadata["entities"] = str(entities)
documents.append(Document(
        id_=str(s['id']),
        text=s.get('bodytext', ''),
        metadata=metadata
}
my concern is, that I won't be able to look up items within these converted arrays later via:
Plain Text
query_engine = index.as_query_engine(
    similarity_top_k=3,
    filters=MetadataFilters(
        filters=[
            ExactMatchFilter(key="user_id", value="12345")
        ]
    ),
)
for instance, how would I look for a particular entity if the list becomes a continuous string?
just checked
was hoping for some type coerson but no
data goes as string instead of list into pinecone
Attachment
Screenshot_2023-08-08_at_08.50.21.png
Yea I agree for sure. This is just a temp workaround since llama-index is being strict about the types.
Likely need to figure out a better implementation for pinecone, but for now, it's not going work well πŸ™‚
I understand, thanks for the info πŸ™‚
Add a reply
Sign up and join the conversation on Discord