MCPcopy Index your code
hub / github.com/golang/example / decodeGetResults

Function decodeGetResults

ragserver/ragserver/main.go:219–246  ·  view source on GitHub ↗

decodeGetResults decodes the result returned by Weaviate's GraphQL Get query; these are returned as a nested map[string]any (just like JSON unmarshaled into a map[string]any). We have to extract all document contents as a list of strings.

(result *models.GraphQLResponse)

Source from the content-addressed store, hash-verified

217// unmarshaled into a map[string]any). We have to extract all document contents
218// as a list of strings.
219func decodeGetResults(result *models.GraphQLResponse) ([]string, error) {
220 data, ok := result.Data["Get"]
221 if !ok {
222 return nil, fmt.Errorf("Get key not found in result")
223 }
224 doc, ok := data.(map[string]any)
225 if !ok {
226 return nil, fmt.Errorf("Get key unexpected type")
227 }
228 slc, ok := doc["Document"].([]any)
229 if !ok {
230 return nil, fmt.Errorf("Document is not a list of results")
231 }
232
233 var out []string
234 for _, s := range slc {
235 smap, ok := s.(map[string]any)
236 if !ok {
237 return nil, fmt.Errorf("invalid element in list of documents")
238 }
239 s, ok := smap["text"].(string)
240 if !ok {
241 return nil, fmt.Errorf("expected string in list of documents")
242 }
243 out = append(out, s)
244 }
245 return out, nil
246}

Callers 1

queryHandlerMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…