MCPcopy Create free account
hub / github.com/InferCore/InferCore / parseMeilisearchHits

Function parseMeilisearchHits

internal/retrieval/meilisearch_kb.go:82–116  ·  view source on GitHub ↗
(b []byte)

Source from the content-addressed store, hash-verified

80}
81
82func parseMeilisearchHits(b []byte) (types.RetrievalResult, error) {
83 var root struct {
84 Hits []json.RawMessage `json:"hits"`
85 }
86 if err := json.Unmarshal(b, &root); err != nil {
87 return types.RetrievalResult{}, fmt.Errorf("meilisearch decode: %w", err)
88 }
89 var out []types.RetrievalChunk
90 for i, raw := range root.Hits {
91 var hit map[string]any
92 if err := json.Unmarshal(raw, &hit); err != nil {
93 continue
94 }
95 // Meilisearch returns document fields at top level; optional _formatted
96 text := firstString(hit, "text", "content", "body", "passage")
97 if text == "" {
98 if fmted, ok := hit["_formatted"].(map[string]any); ok {
99 text = firstString(fmted, "text", "content", "body", "passage")
100 }
101 }
102 if text == "" {
103 continue
104 }
105 var score float64
106 if s, ok := hit["_rankingScore"].(float64); ok {
107 score = s
108 }
109 src := fmt.Sprintf("hit:%d", i)
110 if id, ok := hit["id"].(string); ok && id != "" {
111 src = id
112 }
113 out = append(out, types.RetrievalChunk{Text: text, Source: src, Score: score})
114 }
115 return types.RetrievalResult{Chunks: out}, nil
116}

Callers 2

TestParseMeilisearchHitsFunction · 0.85
RetrieveMethod · 0.85

Calls 1

firstStringFunction · 0.85

Tested by 1

TestParseMeilisearchHitsFunction · 0.68