pinecone-io / go-pinecone

Pinecone.io Golang Client
Apache License 2.0
49 stars 9 forks source link

[Docs] Missing example for how to do $and and $or filters #68

Open assembly-winston opened 3 months ago

assembly-winston commented 3 months ago

There is no example for how to do these filters in the docs. When doing the suggested example from the general pinecone example and translating to Go, structpb package complains that []map[string]any is not a valid type:

{"$and": [{"genre": "comedy"}, {"genre":"documentary"}]}
anawishnoff commented 1 month ago

@jseldess Would you be able to take a look?

jseldess commented 1 month ago

Sure, @anawishnoff. I'll take a look soon.

jseldess commented 1 month ago

@assembly-winston, thanks for reporting this gap in our docs. We'll work on adding SDK-specific filtering examples, but in the meantime, this should work for your example above:

    queryMetadataMap := map[string]interface{}{
        "$and": []interface{}{
            map[string]interface{}{
                "genre": map[string]interface{}{
                    "$eq": "comedy",
                },
            },
            map[string]interface{}{
                "genre": map[string]interface{}{
                    "$eq": "documentary",
                },
            },
        },
    }

    metadataFilter, err := structpb.NewStruct(queryMetadataMap)
    if err != nil {
        log.Fatalf("Failed to create metadata filter: %v", err)
    }