Spaces:
Build error
Build error
Create embedding_generation.py
Browse files- embedding_generation.py +12 -0
embedding_generation.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pandas as pd
|
| 2 |
+
import get_embedding from openai_api
|
| 3 |
+
|
| 4 |
+
def compute_doc_embeddings(df: pd.DataFrame) -> dict[tuple[str, str], list[float]]:
|
| 5 |
+
"""
|
| 6 |
+
Create an embedding for each row in the dataframe using the OpenAI Embeddings API.
|
| 7 |
+
|
| 8 |
+
Return a dictionary that maps between each embedding vector and the index of the row that it corresponds to.
|
| 9 |
+
"""
|
| 10 |
+
return {
|
| 11 |
+
idx: get_embedding(r.description) for idx, r in df.iterrows()
|
| 12 |
+
}
|