Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 23 additions & 32 deletions pinecone/index_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1874,18 +1874,7 @@ func (idx *IndexConnection) CreateNamespace(ctx context.Context, in *CreateNames
return nil, err
}

nsDesc := &NamespaceDescription{
Name: res.Name,
RecordCount: res.RecordCount,
Schema: toMetadataSchemaGrpc(res.Schema),
}

if res.IndexedFields != nil {
nsDesc.IndexedFields = &IndexedFields{
Fields: res.IndexedFields.Fields,
}
}
return nsDesc, nil
return toNamespaceDescription(res), nil
}

// [IndexConnection.DescribeNamespace] describes a namespace within a serverless index.
Expand Down Expand Up @@ -1929,23 +1918,8 @@ func (idx *IndexConnection) DescribeNamespace(ctx context.Context, namespace str
if err != nil {
return nil, err
}
if res == nil {
return nil, nil
}

nsDesc := &NamespaceDescription{
Name: res.Name,
RecordCount: res.RecordCount,
Schema: toMetadataSchemaGrpc(res.Schema),
}

if res.IndexedFields != nil {
nsDesc.IndexedFields = &IndexedFields{
Fields: res.IndexedFields.Fields,
}
}

return nsDesc, nil
return toNamespaceDescription(res), nil
}

// [ListNamespacesResponse] is returned by the [IndexConnection.ListNamespaces] method.
Expand Down Expand Up @@ -2286,10 +2260,7 @@ func toListNamespacesResponse(listNamespacesResponse *db_data_grpc.ListNamespace

namespaces := make([]*NamespaceDescription, len(listNamespacesResponse.Namespaces))
for i, ns := range listNamespacesResponse.Namespaces {
namespaces[i] = &NamespaceDescription{
Name: ns.Name,
RecordCount: ns.RecordCount,
}
namespaces[i] = toNamespaceDescription(ns)
}
var pagination *Pagination
if listNamespacesResponse.Pagination != nil {
Expand All @@ -2305,6 +2276,26 @@ func toListNamespacesResponse(listNamespacesResponse *db_data_grpc.ListNamespace
}
}

func toNamespaceDescription(ns *db_data_grpc.NamespaceDescription) *NamespaceDescription {
if ns == nil {
return nil
}

nsDesc := &NamespaceDescription{
Name: ns.Name,
RecordCount: ns.RecordCount,
Schema: toMetadataSchemaGrpc(ns.Schema),
}

if ns.IndexedFields != nil {
nsDesc.IndexedFields = &IndexedFields{
Fields: ns.IndexedFields.Fields,
}
}

return nsDesc
}

func vecToGrpc(v *Vector) *db_data_grpc.Vector {
if v == nil {
return nil
Expand Down