feat(oss): port v3 pipeline with hybrid search, entity extraction, and additive scoring (#4805)
Co-authored-by: Soumil Rathi <soumilrathi@gmail.com> Co-authored-by: Saket Aryan <saketaryan2002@gmail.com> Co-authored-by: chaithanyak42 <chaithanya.kumar42a@gmail.com> Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
co-authored by
Soumil Rathi
Saket Aryan
chaithanyak42
kartik-mem0
parent
57f944e18a
commit
a488e19044
@@ -53,3 +53,24 @@ class OpenAIEmbedding(EmbeddingBase):
|
||||
if self._pass_dimensions_to_api:
|
||||
kwargs["dimensions"] = self.config.embedding_dims
|
||||
return self.client.embeddings.create(**kwargs).data[0].embedding
|
||||
|
||||
def embed_batch(self, texts, memory_action="add"):
|
||||
"""Embed multiple texts in a single OpenAI API call.
|
||||
|
||||
Automatically chunks into batches of 100 to stay within API limits.
|
||||
"""
|
||||
MAX_BATCH = 100
|
||||
texts = [text.replace("\n", " ") for text in texts]
|
||||
all_embeddings = []
|
||||
for i in range(0, len(texts), MAX_BATCH):
|
||||
chunk = texts[i : i + MAX_BATCH]
|
||||
kwargs = {
|
||||
"input": chunk,
|
||||
"model": self.config.model,
|
||||
"encoding_format": "float",
|
||||
}
|
||||
if self._pass_dimensions_to_api:
|
||||
kwargs["dimensions"] = self.config.embedding_dims
|
||||
response = self.client.embeddings.create(**kwargs)
|
||||
all_embeddings.extend(item.embedding for item in sorted(response.data, key=lambda x: x.index))
|
||||
return all_embeddings
|
||||
|
||||
Reference in New Issue
Block a user