mml458
December 4, 2023, 5:05pm
1
Hello,
Until last week I had been using text-embedding-ada-002 without issue. Suddenly my line of code “from openai.embeddings_utils import get_embedding” is giving me a consistent error saying utils module does not exist. I changed the line of code to match what is used in the OpenAI cookbook blogpost on ada-002 however the error remains. Has ada-002 changed recently? I had been using this exact same code successfully for three months with 0 issues. Any advice or suggestions would be greatly appreciated.
1 Like
sps
December 4, 2023, 5:32pm
2
Welcome to the dev forum @mml458
If you recently upgraded the openai py package to v1.0 or higher then this won’t work.
See:
opened 01:09PM - 06 Nov 23 UTC
closed 01:55PM - 06 Nov 23 UTC
### Describe the bug
The previous version of the OpenAI Python library contai… ned `embeddings_utils.py` which provided functions like `cosine_similarity` which are used for semantic text search with embeddings. Without this functionality existing code including OpenAI's cookbook example: https://cookbook.openai.com/examples/semantic_text_search_using_embeddings will fail due to this dependency.
Are there plans to add this support back-in or should we just create our own cosine_similarity function based on the one that was present in `embeddings_utils`:
```python
def cosine_similarity(a, b):
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
```
### To Reproduce
Cookbook example cannot be converted to use v1.0 without removing the dependency on `embeddings_utils.py` https://cookbook.openai.com/examples/semantic_text_search_using_embeddings
### Code snippets
```Python
from openai.embeddings_utils import get_embedding, cosine_similarity
# search through the reviews for a specific product
def search_reviews(df, product_description, n=3, pprint=True):
product_embedding = get_embedding(
product_description,
engine="text-embedding-ada-002"
)
df["similarity"] = df.embedding.apply(lambda x: cosine_similarity(x, product_embedding))
results = (
df.sort_values("similarity", ascending=False)
.head(n)
.combined.str.replace("Title: ", "")
.str.replace("; Content:", ": ")
)
if pprint:
for r in results:
print(r[:200])
print()
return results
results = search_reviews(df, "delicious beans", n=3)
```
### OS
Windows
### Python version
Python v3.10.11
### Library version
openai-python==1.0.0rc2
1 Like
Kunal.T
February 10, 2024, 7:09am
3
This document still uses openai.embeddings_utils
as of now.
1 Like