Skip to content

Commit

Permalink
fix OpenAI Embedding length error (#1972)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?
 
#1958   fix OpenAI Embedding length error

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)

---------

Co-authored-by: Zhedong Cen <[email protected]>
  • Loading branch information
hangters and aopstudio authored Aug 16, 2024
1 parent 5b5e367 commit b4ef50b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions rag/llm/embedding_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def __init__(self, key, model_name="text-embedding-ada-002",
self.model_name = model_name

def encode(self, texts: list, batch_size=32):
texts = [truncate(t, 8196) for t in texts]
texts = [truncate(t, 8191) for t in texts]
res = self.client.embeddings.create(input=texts,
model=self.model_name)
return np.array([d.embedding for d in res.data]
), res.usage.total_tokens

def encode_queries(self, text):
res = self.client.embeddings.create(input=[truncate(text, 8196)],
res = self.client.embeddings.create(input=[truncate(text, 8191)],
model=self.model_name)
return np.array(res.data[0].embedding), res.usage.total_tokens

Expand Down

0 comments on commit b4ef50b

Please sign in to comment.