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

Add DotProduct Method and README Example for Embedding Similarity Search #492

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

ealvar3z
Copy link
Contributor

Describe the change

  • Implement a DotProduct() method for the Embedding struct to calculate the dot product between two embeddings.
  • Add a custom error type for vector length mismatch.

Describe your solution

  • Finish implementing the following requested changes from @sashabaranov:
We don't need two huge examples [see](https://github.com/sashabaranov/go-openai/pull/274/files#r1232058195) — Please make one small example without encoding/gob etc.
I'm not sure this change is relevant [here](https://github.com/sashabaranov/go-openai/pull/274/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L596)
Let's make DotProduct a method of Embedding struct [see](https://github.com/sashabaranov/go-openai/pull/274/files#r1232242888)

Tests

  • Add unit tests to validate the new DotProduct() method and error handling.

Additional context

  • Update README.md with a complete example demonstrating how to perform an embedding similarity search for user queries.

Issue: #XXXX

- Implement a DotProduct() method for the Embedding struct to calculate the dot product between two embeddings.
- Add a custom error type for vector length mismatch.
- Update README.md with a complete example demonstrating how to perform an embedding similarity search for user queries.
- Add unit tests to validate the new DotProduct() method and error handling.
@codecov
Copy link

codecov bot commented Sep 13, 2023

Codecov Report

Merging #492 (4a7e7c0) into master (3589837) will increase coverage by 0.15%.
Report is 1 commits behind head on master.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #492      +/-   ##
==========================================
+ Coverage   97.30%   97.46%   +0.15%     
==========================================
  Files          18       18              
  Lines         780      829      +49     
==========================================
+ Hits          759      808      +49     
  Misses         15       15              
  Partials        6        6              
Files Changed Coverage Δ
embeddings.go 100.00% <100.00%> (ø)

@sashabaranov
Copy link
Owner

Thank you so much, this was coming for a long time :D

README.md Outdated Show resolved Hide resolved
@sashabaranov sashabaranov merged commit 84f77a0 into sashabaranov:master Oct 2, 2023
3 checks passed
mudler referenced this pull request in mudler/LocalAI Oct 14, 2023
…#1159)

[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[github.com/sashabaranov/go-openai](https://togithub.com/sashabaranov/go-openai)
| require | minor | `v1.15.4` -> `v1.16.0` |

---

### Release Notes

<details>
<summary>sashabaranov/go-openai
(github.com/sashabaranov/go-openai)</summary>

###
[`v1.16.0`](https://togithub.com/sashabaranov/go-openai/releases/tag/v1.16.0)

[Compare
Source](https://togithub.com/sashabaranov/go-openai/compare/v1.15.4...v1.16.0)

#### What's Changed

- Add DotProduct Method and README Example for Embedding Similarity
Search by [@&#8203;ealvar3z](https://togithub.com/ealvar3z) in
[https://github.com/sashabaranov/go-openai/pull/492](https://togithub.com/sashabaranov/go-openai/pull/492)
- fix: use any for n_epochs by
[@&#8203;henomis](https://togithub.com/henomis) in
[https://github.com/sashabaranov/go-openai/pull/499](https://togithub.com/sashabaranov/go-openai/pull/499)
- Feat Add headers to openai responses by
[@&#8203;henomis](https://togithub.com/henomis) in
[https://github.com/sashabaranov/go-openai/pull/506](https://togithub.com/sashabaranov/go-openai/pull/506)
- Support get http header and x-ratelimit-\* headers by
[@&#8203;liushuangls](https://togithub.com/liushuangls) in
[https://github.com/sashabaranov/go-openai/pull/507](https://togithub.com/sashabaranov/go-openai/pull/507)

**Full Changelog**:
sashabaranov/go-openai@v1.15.4...v1.16.0

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/go-skynet/LocalAI).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44LjEiLCJ1cGRhdGVkSW5WZXIiOiIzNy44LjEiLCJ0YXJnZXRCcmFuY2giOiJtYXN0ZXIifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants