MCPcopy Create free account
hub / github.com/compozy/agh / SearchMemory

Method SearchMemory

internal/api/core/memory.go:143–218  ·  view source on GitHub ↗

SearchMemory returns ranked durable memory matches.

(c *gin.Context)

Source from the content-addressed store, hash-verified

141
142// SearchMemory returns ranked durable memory matches.
143func (h *BaseHandlers) SearchMemory(c *gin.Context) {
144 if h.MemoryStore == nil {
145 h.respondMemoryError(c, http.StatusInternalServerError, errors.New("memory store is not configured"), nil)
146 return
147 }
148
149 var req contract.MemorySearchRequest
150 if err := c.ShouldBindJSON(&req); err != nil {
151 h.respondMemoryError(
152 c,
153 http.StatusBadRequest,
154 fmt.Errorf("%s: decode memory search request: %w", h.transportName(), err),
155 nil,
156 )
157 return
158 }
159 if strings.TrimSpace(req.QueryText) == "" {
160 err := NewMemoryValidationError(errors.New("query_text is required"))
161 h.respondMemoryError(c, StatusForMemoryError(err), err, nil)
162 return
163 }
164
165 selector, err := h.resolveMemorySelector(c.Request.Context(), memorySelector{
166 Scope: req.Scope,
167 WorkspaceID: req.WorkspaceID,
168 AgentName: req.AgentName,
169 AgentTier: req.AgentTier,
170 }, false)
171 if err != nil {
172 h.respondMemoryError(c, StatusForMemoryError(err), err, nil)
173 return
174 }
175 selector.Scope = defaultMemorySelectorScope(selector)
176 store, err := h.memoryRecallStoreForSelector(c.Request.Context(), selector)
177 if err != nil {
178 h.respondMemoryError(c, StatusForMemoryError(err), err, nil)
179 return
180 }
181 recallWorkspaceID := memoryRecallQueryWorkspaceID(selector)
182 recall, err := store.Recall(c.Request.Context(), memcontract.Query{
183 WorkspaceID: recallWorkspaceID,
184 AgentName: selector.AgentName,
185 QueryText: req.QueryText,
186 ContextHint: req.ContextHint,
187 }, memcontract.RecallOptions{
188 TopK: req.TopK,
189 RawCandidates: req.RawCandidates,
190 IncludeAlreadySurfaced: req.IncludeAlreadySurfaced,
191 IncludeSystem: req.IncludeSystem,
192 AlreadySurfaced: req.AlreadySurfaced,
193 AllowTrivialQuery: true,
194 })
195 if err != nil {
196 h.respondMemoryError(c, StatusForMemoryError(err), err, nil)
197 return
198 }
199 results := memorySearchResultPayloads(recall)
200 if len(results) == 0 {

Callers

nothing calls this directly

Calls 12

respondMemoryErrorMethod · 0.95
transportNameMethod · 0.95
resolveMemorySelectorMethod · 0.95
NewMemoryValidationErrorFunction · 0.85
StatusForMemoryErrorFunction · 0.85
RecallMethod · 0.65

Tested by

no test coverage detected