From 294f2e750fa76075b3ae86bd4f0c196ff137ef08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 28 Nov 2024 16:49:35 +0100 Subject: [PATCH 1/4] fix(vectorstores:weaviate): do not return error when zero documents are retrieved --- vectorstores/weaviate/weaviate.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/vectorstores/weaviate/weaviate.go b/vectorstores/weaviate/weaviate.go index 55790deca..4249d19db 100644 --- a/vectorstores/weaviate/weaviate.go +++ b/vectorstores/weaviate/weaviate.go @@ -232,10 +232,12 @@ func (s Store) parseDocumentsByGraphQLResponse(res *models.GraphQLResponse) ([]s return nil, ErrEmptyResponse } items, ok := data.([]any) + + var docs []schema.Document if !ok || len(items) == 0 { - return nil, ErrEmptyResponse + return docs, nil } - docs := make([]schema.Document, 0, len(items)) + docs = make([]schema.Document, 0, len(items)) for _, item := range items { itemMap, ok := item.(map[string]any) if !ok { From 6bce8b186231f476ad90f3f43f8d214216712bbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Thu, 28 Nov 2024 19:56:45 +0100 Subject: [PATCH 2/4] fix: pre-allocate with items' length --- vectorstores/weaviate/weaviate.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vectorstores/weaviate/weaviate.go b/vectorstores/weaviate/weaviate.go index 4249d19db..1160ff316 100644 --- a/vectorstores/weaviate/weaviate.go +++ b/vectorstores/weaviate/weaviate.go @@ -233,11 +233,10 @@ func (s Store) parseDocumentsByGraphQLResponse(res *models.GraphQLResponse) ([]s } items, ok := data.([]any) - var docs []schema.Document + docs := make([]schema.Document, 0, len(items)) if !ok || len(items) == 0 { return docs, nil } - docs = make([]schema.Document, 0, len(items)) for _, item := range items { itemMap, ok := item.(map[string]any) if !ok { From eff3cb8fa000d0ac9e193adbfc320c182524a1ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 7 Jan 2025 08:48:26 +0100 Subject: [PATCH 3/4] fix(vectorstores:pinecone): do not return error when zero documents are retrieved --- vectorstores/pinecone/pinecone.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vectorstores/pinecone/pinecone.go b/vectorstores/pinecone/pinecone.go index 1b22f553a..b50004078 100644 --- a/vectorstores/pinecone/pinecone.go +++ b/vectorstores/pinecone/pinecone.go @@ -170,7 +170,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) From 47f0208d208c2d23ba45ee75a2bc0068c07da9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Tue, 7 Jan 2025 08:48:40 +0100 Subject: [PATCH 4/4] chore(vectorstores:pinecone): deprecate not-used error --- vectorstores/pinecone/pinecone.go | 1 + 1 file changed, 1 insertion(+) diff --git a/vectorstores/pinecone/pinecone.go b/vectorstores/pinecone/pinecone.go index b50004078..8bc47b6af 100644 --- a/vectorstores/pinecone/pinecone.go +++ b/vectorstores/pinecone/pinecone.go @@ -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(