MCPcopy
hub / github.com/weaviate/weaviate / Query

Method Query

usecases/objects/query.go:69–125  ·  view source on GitHub ↗
(ctx context.Context, principal *models.Principal, params *QueryParams,
)

Source from the content-addressed store, hash-verified

67}
68
69func (m *Manager) Query(ctx context.Context, principal *models.Principal, params *QueryParams,
70) ([]*models.Object, *Error) {
71 class := "*"
72
73 if params != nil && params.Class != "" {
74 resolved, _, err := m.resolveNS(principal, params.Class)
75 if err != nil {
76 return nil, &Error{err.Error(), StatusUnprocessableEntity, err}
77 }
78 params.Class = resolved
79 class = params.Class
80 }
81
82 if err := m.authorizer.Authorize(ctx, principal, authorization.READ, authorization.CollectionsData(class)...); err != nil {
83 return nil, &Error{err.Error(), StatusForbidden, err}
84 }
85
86 m.metrics.GetObjectInc()
87 defer m.metrics.GetObjectDec()
88
89 q, err := params.inputs(m)
90 if err != nil {
91 return nil, &Error{"offset or limit", StatusBadRequest, err}
92 }
93
94 filteredQuery := filter.New[*QueryInput](m.authorizer, m.config.Config.Authorization.Rbac).Filter(
95 ctx,
96 principal,
97 []*QueryInput{q},
98 authorization.READ,
99 func(qi *QueryInput) string {
100 return authorization.CollectionsData(qi.Class)[0]
101 },
102 )
103 if len(filteredQuery) == 0 {
104 err = fmt.Errorf("unauthorized to access collection %s", q.Class)
105 return nil, &Error{err.Error(), StatusForbidden, err}
106 }
107
108 res, rerr := m.vectorRepo.Query(ctx, filteredQuery[0])
109 if rerr != nil {
110 return nil, rerr
111 }
112
113 if m.modulesProvider != nil {
114 res, err = m.modulesProvider.ListObjectsAdditionalExtend(ctx, res, q.Additional.ModuleParams)
115 if err != nil {
116 return nil, &Error{"extend results", StatusInternalServerError, err}
117 }
118 }
119
120 if q.Additional.Vector {
121 m.trackUsageList(res)
122 }
123
124 return res.ObjectsWithVector(q.Additional.Vector), nil
125}

Callers

nothing calls this directly

Calls 13

resolveNSMethod · 0.95
trackUsageListMethod · 0.95
CollectionsDataFunction · 0.92
inputsMethod · 0.80
ErrorfMethod · 0.80
ObjectsWithVectorMethod · 0.80
AuthorizeMethod · 0.65
GetObjectIncMethod · 0.65
GetObjectDecMethod · 0.65
QueryMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected