Skip to content

Commit

Permalink
Merge pull request #1077 from mdelapenya/weaviate-return-no-errors
Browse files Browse the repository at this point in the history
fix(vectorstores:weaviate|pinecone): do not return error when zero documents are retrieved
  • Loading branch information
FluffyKebab authored Jan 7, 2025
2 parents f1fde1f + 47f0208 commit bc77e45
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion vectorstores/pinecone/pinecone.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
ErrEmbedderWrongNumberVectors = errors.New(
"number of vectors from embedder does not match number of documents",
)
// Deprecated: ErrEmptyResponse is not used anymore and will be removed in the future.
// ErrEmptyResponse is returned if the API gives an empty response.
ErrEmptyResponse = errors.New("empty response")
ErrInvalidScoreThreshold = errors.New(
Expand Down Expand Up @@ -170,7 +171,7 @@ func (s Store) SimilaritySearch(ctx context.Context, query string, numDocuments
}

if len(queryResult.Matches) == 0 {
return nil, ErrEmptyResponse
return []schema.Document{}, nil
}

return s.getDocumentsFromMatches(queryResult, scoreThreshold)
Expand Down
5 changes: 3 additions & 2 deletions vectorstores/weaviate/weaviate.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,11 @@ func (s Store) parseDocumentsByGraphQLResponse(res *models.GraphQLResponse) ([]s
return nil, ErrEmptyResponse
}
items, ok := data.([]any)

docs := make([]schema.Document, 0, len(items))
if !ok || len(items) == 0 {
return nil, ErrEmptyResponse
return docs, nil
}
docs := make([]schema.Document, 0, len(items))
for _, item := range items {
itemMap, ok := item.(map[string]any)
if !ok {
Expand Down

0 comments on commit bc77e45

Please sign in to comment.