henomis/lingoose

Code Panics when embeddings slice is empty

Closed this issue · 1 comments

Describe the bug
When using Voyage AI as an embedder the code panics due to an index out of range error because we're assuming embeddings has length of at least 1.

func (i *Index) Query(ctx context.Context, query string, opts ...option.Option) (SearchResults, error) {
	embeddings, err := i.embedder.Embed(ctx, []string{query})
	if err != nil {
		return nil, err
	}
	return i.Search(ctx, embeddings[0], opts...)
}

I would. check the length of embeddings here to guard against it. And maybe also it's implementations as a secondary guard.
Not sure why I got a length of 0, but still panicking should not be the desired behaviour.

Thanks again though.

fixed here: #200