github.com/instill-ai/component@v0.16.0-beta/pkg/connector/pinecone/v0/structs.go (about) 1 package pinecone 2 3 type queryInput struct { 4 Namespace string `json:"namespace"` 5 TopK int64 `json:"top_k"` 6 Vector []float64 `json:"vector"` 7 IncludeValues bool `json:"include_values"` 8 IncludeMetadata bool `json:"include_metadata"` 9 ID string `json:"id"` 10 Filter interface{} `json:"filter"` 11 MinScore float64 `json:"min_score"` 12 } 13 14 type queryReq struct { 15 Namespace string `json:"namespace"` 16 TopK int64 `json:"topK"` 17 Vector []float64 `json:"vector,omitempty"` 18 IncludeValues bool `json:"includeValues"` 19 IncludeMetadata bool `json:"includeMetadata"` 20 ID string `json:"id,omitempty"` 21 Filter interface{} `json:"filter,omitempty"` 22 } 23 24 func (q queryInput) asRequest() queryReq { 25 return queryReq{ 26 Namespace: q.Namespace, 27 TopK: q.TopK, 28 Vector: q.Vector, 29 IncludeValues: q.IncludeValues, 30 IncludeMetadata: q.IncludeMetadata, 31 ID: q.ID, 32 Filter: q.Filter, 33 } 34 } 35 36 type queryResp struct { 37 Namespace string `json:"namespace"` 38 Matches []match `json:"matches"` 39 } 40 41 func (r queryResp) filterOutBelowThreshold(th float64) queryResp { 42 if th <= 0 { 43 return r 44 } 45 46 matches := make([]match, 0, len(r.Matches)) 47 for _, match := range r.Matches { 48 if match.Score >= th { 49 matches = append(matches, match) 50 } 51 } 52 r.Matches = matches 53 54 return r 55 } 56 57 type match struct { 58 vector 59 Score float64 `json:"score"` 60 } 61 62 type upsertReq struct { 63 Vectors []vector `json:"vectors"` 64 Namespace string `json:"namespace,omitempty"` 65 } 66 67 type upsertInput struct { 68 vector 69 Namespace string `json:"namespace"` 70 } 71 72 type vector struct { 73 ID string `json:"id"` 74 Values []float64 `json:"values,omitempty"` 75 Metadata interface{} `json:"metadata,omitempty"` 76 } 77 78 type upsertResp struct { 79 RecordsUpserted int64 `json:"upsertedCount"` 80 } 81 82 type upsertOutput struct { 83 RecordsUpserted int64 `json:"upserted_count"` 84 } 85 86 type errBody struct { 87 Msg string `json:"message"` 88 } 89 90 func (e errBody) Message() string { 91 return e.Msg 92 }