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:
soumil-rathi
2026-04-14 18:00:58 +05:30
committed by GitHub
co-authored by Soumil Rathi Saket Aryan chaithanyak42 kartik-mem0
parent 57f944e18a
commit a488e19044
120 changed files with 10107 additions and 17135 deletions
+17
View File
@@ -53,3 +53,20 @@ class AzureOpenAIEmbedding(EmbeddingBase):
"""
text = text.replace("\n", " ")
return self.client.embeddings.create(input=[text], model=self.config.model).data[0].embedding
def embed_batch(self, texts, memory_action="add"):
"""Embed multiple texts in a single Azure 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]
response = self.client.embeddings.create(
input=chunk,
model=self.config.model,
)
all_embeddings.extend(item.embedding for item in sorted(response.data, key=lambda x: x.index))
return all_embeddings
+16
View File
@@ -29,3 +29,19 @@ class EmbeddingBase(ABC):
list: The embedding vector.
"""
pass
def embed_batch(self, texts, memory_action="add"):
"""Embed multiple texts. Override in subclasses for native batch support.
Default implementation calls embed() sequentially for each text.
Subclasses with native batch APIs (e.g., OpenAI) should override
this for better performance.
Args:
texts: List of text strings to embed.
memory_action: The action context ("add", "search", "update").
Returns:
List of embedding vectors (list of floats), one per input text.
"""
return [self.embed(text, memory_action) for text in texts]
+21
View File
@@ -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