| 99 | } |
| 100 | |
| 101 | func parseHTTPChunksJSON(b []byte) (types.RetrievalResult, error) { |
| 102 | var env httpChunksEnvelope |
| 103 | if err := json.Unmarshal(b, &env); err != nil { |
| 104 | return types.RetrievalResult{}, fmt.Errorf("decode retrieval json: %w", err) |
| 105 | } |
| 106 | list := env.Chunks |
| 107 | if len(list) == 0 { |
| 108 | list = env.Results |
| 109 | } |
| 110 | out := make([]types.RetrievalChunk, 0, len(list)) |
| 111 | for _, el := range list { |
| 112 | text := strings.TrimSpace(el.Text) |
| 113 | if text == "" { |
| 114 | text = strings.TrimSpace(el.Content) |
| 115 | } |
| 116 | if text == "" { |
| 117 | continue |
| 118 | } |
| 119 | out = append(out, types.RetrievalChunk{ |
| 120 | Text: text, |
| 121 | Source: el.Source, |
| 122 | Score: el.Score, |
| 123 | }) |
| 124 | } |
| 125 | return types.RetrievalResult{Chunks: out}, nil |
| 126 | } |