Skip to content

Commit cf6eee2

Browse files
add MetadataFilter and Metadata helpers, fix integration tests
1 parent 571e468 commit cf6eee2

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pinecone/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ type ConfigureIndexEmbed struct {
12221222
//
12231223
// [scale a pods-based index]: https://docs.pinecone.io/guides/indexes/configure-pod-based-indexes
12241224
func (c *Client) ConfigureIndex(ctx context.Context, name string, in ConfigureIndexParams) (*Index, error) {
1225-
if in.PodType == "" && in.Replicas == 0 && in.DeletionProtection == "" && in.Tags == nil {
1225+
if in.PodType == "" && in.Replicas == 0 && in.DeletionProtection == "" && in.Tags == nil && in.ReadCapacity == nil {
12261226
return nil, fmt.Errorf("must specify PodType, Replicas, DeletionProtection, or Tags when configuring an index")
12271227
}
12281228

@@ -2987,6 +2987,7 @@ func readCapacityRequestToReadCapacity(request *ReadCapacityRequest) (*db_contro
29872987

29882988
// Scaling if provided
29892989
if request.Dedicated.Scaling != nil && request.Dedicated.Scaling.Manual != nil {
2990+
dedicatedConfig.Scaling = "Manual"
29902991
dedicatedConfig.Manual = &db_control.ScalingConfigManual{
29912992
Replicas: request.Dedicated.Scaling.Manual.Replicas,
29922993
Shards: request.Dedicated.Scaling.Manual.Shards,

pinecone/models.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,61 @@ type MetadataFilter = structpb.Struct
376376
// [attached to, or updated for, a vector]: https://docs.pinecone.io/guides/data/filter-with-metadata#inserting-metadata-into-an-index
377377
type Metadata = structpb.Struct
378378

379+
// [NewMetadataFilter] creates a [MetadataFilter] from a map of key-value pairs representing metadata filter expressions.
380+
// This helper function eliminates the need to import and use [structpb.Struct] directly.
381+
//
382+
// The input map should contain metadata filter expressions using Pinecone's filtering operators
383+
// (e.g., $eq, $ne, $gt, $gte, $lt, $lte, $in, $nin, $exists, $and, $or).
384+
//
385+
// Example:
386+
//
387+
// filterMap := map[string]interface{}{
388+
// "genre": map[string]interface{}{
389+
// "$eq": "documentary",
390+
// },
391+
// "year": map[string]interface{}{
392+
// "$gte": 2020,
393+
// },
394+
// }
395+
// filter, err := pinecone.NewMetadataFilter(filterMap)
396+
//
397+
// [MetadataFilter]: https://docs.pinecone.io/guides/data/filter-with-metadata#querying-an-index-with-metadata-filters
398+
func NewMetadataFilter(m map[string]interface{}) (*MetadataFilter, error) {
399+
s, err := structpb.NewStruct(m)
400+
if err != nil {
401+
return nil, err
402+
}
403+
return s, nil
404+
}
405+
406+
// [NewMetadata] creates [Metadata] from a map of key-value pairs representing metadata fields.
407+
// This helper function eliminates the need to import and use [structpb.Struct] directly.
408+
//
409+
// The input map should contain flat key-value pairs where:
410+
// - Keys must be strings and must not start with a $
411+
// - Values must be one of: string, integer, floating point, boolean, or list of strings
412+
// - Nested JSON objects are not supported
413+
// - Null values are not supported (remove keys instead)
414+
//
415+
// Example:
416+
//
417+
// metadataMap := map[string]interface{}{
418+
// "genre": "classical",
419+
// "year": 2020,
420+
// "is_public": true,
421+
// "tags": []string{"beginner", "database"},
422+
// }
423+
// metadata, err := pinecone.NewMetadata(metadataMap)
424+
//
425+
// [Metadata]: https://docs.pinecone.io/guides/data/filter-with-metadata#inserting-metadata-into-an-index
426+
func NewMetadata(m map[string]interface{}) (*Metadata, error) {
427+
s, err := structpb.NewStruct(m)
428+
if err != nil {
429+
return nil, err
430+
}
431+
return s, nil
432+
}
433+
379434
// [Embedding] represents the embedding of a single input which is returned after [generating embeddings].
380435
// [Embedding] is a tagged union which can have either a [SparseEmbedding] or a [DenseEmbedding].
381436
//

0 commit comments

Comments
 (0)