Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Return empty results on Memory Search with no results #274

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions pkg/server/apihandlers/memory_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,6 @@ func SearchMemoryHandler(appState *models.AppState) http.HandlerFunc {
handlertools.RenderError(w, err, http.StatusInternalServerError)
return
}
if searchResult == nil {
handlertools.RenderError(w, fmt.Errorf("not found"), http.StatusNotFound)
return
}
if err := handlertools.EncodeJSON(w, searchResult); err != nil {
handlertools.RenderError(w, err, http.StatusInternalServerError)
return
Expand Down
15 changes: 13 additions & 2 deletions pkg/store/postgres/search_memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"math"

"github.com/getzep/zep/pkg/llms"
Expand Down Expand Up @@ -100,6 +101,11 @@ func searchMemory(
return nil, store.NewStorageError("memory searchMemory failed", err)
}

// If we didn't find any results, return early.
if len(results) == 0 {
return []models.MemorySearchResult{}, nil
}

filteredResults := filterValidMessageSearchResults(results, query.Metadata)

// If we're using MMR, rerank the results.
Expand Down Expand Up @@ -224,8 +230,13 @@ func executeMessagesSearchScan(
dbQuery *bun.SelectQuery,
) ([]models.MemorySearchResult, error) {
var results []models.MemorySearchResult
err := dbQuery.Scan(ctx, &results)
return results, err
if err := dbQuery.Scan(ctx, &results); err != nil {
return nil, fmt.Errorf("error scanning: %w", err)
}
if len(results) == 0 {
return []models.MemorySearchResult{}, nil
}
return results, nil
}

func filterValidMessageSearchResults(
Expand Down
Loading