added simple sanitizer methods for nodes and realtionships (#3021)
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
|
import unicodedata
|
||||||
|
|
||||||
from mem0.memory.utils import format_entities
|
from mem0.memory.utils import format_entities
|
||||||
|
|
||||||
@@ -598,11 +600,17 @@ class MemoryGraph:
|
|||||||
results.append(result)
|
results.append(result)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _remove_spaces_from_entities(self, entity_list):
|
def _sanitize_name(self, name):
|
||||||
|
normalized = unicodedata.normalize('NFKD', name)
|
||||||
|
ascii_text = normalized.encode('ascii', 'ignore').decode('ascii')
|
||||||
|
sanitized = re.sub(r'\W+', '_', ascii_text).lower()
|
||||||
|
return sanitized.strip('_')
|
||||||
|
|
||||||
|
def _sanitize_entities(self, entity_list):
|
||||||
for item in entity_list:
|
for item in entity_list:
|
||||||
item["source"] = item["source"].lower().replace(" ", "_")
|
item["source"] = self._sanitize_name(item["source"])
|
||||||
item["relationship"] = item["relationship"].lower().replace(" ", "_")
|
item["relationship"] = self._sanitize_name(item["relationship"])
|
||||||
item["destination"] = item["destination"].lower().replace(" ", "_")
|
item["destination"] = self._sanitize_name(item["destination"])
|
||||||
return entity_list
|
return entity_list
|
||||||
|
|
||||||
def _search_source_node(self, source_embedding, filters, threshold=0.9):
|
def _search_source_node(self, source_embedding, filters, threshold=0.9):
|
||||||
|
|||||||
Reference in New Issue
Block a user