mem0ai 2.1.4 → 2.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -609,6 +609,24 @@ var EXCLUDED_KEYS = /* @__PURE__ */ new Set([
609
609
  "created_at",
610
610
  "updated_at"
611
611
  ]);
612
+ function toSnakeCase(obj) {
613
+ if (typeof obj !== "object" || obj === null) return obj;
614
+ return Object.fromEntries(
615
+ Object.entries(obj).map(([key, value]) => [
616
+ key.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`),
617
+ value
618
+ ])
619
+ );
620
+ }
621
+ function toCamelCase(obj) {
622
+ if (typeof obj !== "object" || obj === null) return obj;
623
+ return Object.fromEntries(
624
+ Object.entries(obj).map(([key, value]) => [
625
+ key.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()),
626
+ value
627
+ ])
628
+ );
629
+ }
612
630
  var RedisDB = class {
613
631
  constructor(config) {
614
632
  this.indexName = config.collectionName;
@@ -740,7 +758,7 @@ var RedisDB = class {
740
758
  }
741
759
  async insert(vectors, ids, payloads) {
742
760
  const data = vectors.map((vector, idx) => {
743
- const payload = payloads[idx];
761
+ const payload = toSnakeCase(payloads[idx]);
744
762
  const id = ids[idx];
745
763
  const entry = {
746
764
  memory_id: id,
@@ -776,7 +794,8 @@ var RedisDB = class {
776
794
  }
777
795
  }
778
796
  async search(query, limit = 5, filters) {
779
- const filterExpr = filters ? Object.entries(filters).filter(([_, value]) => value !== null).map(([key, value]) => `@${key}:{${value}}`).join(" ") : "*";
797
+ const snakeFilters = filters ? toSnakeCase(filters) : void 0;
798
+ const filterExpr = snakeFilters ? Object.entries(snakeFilters).filter(([_, value]) => value !== null).map(([key, value]) => `@${key}:{${value}}`).join(" ") : "*";
780
799
  const queryVector = new Float32Array(query).buffer;
781
800
  const searchOptions = {
782
801
  PARAMS: {
@@ -790,9 +809,10 @@ var RedisDB = class {
790
809
  "user_id",
791
810
  "memory",
792
811
  "metadata",
793
- "created_at"
812
+ "created_at",
813
+ "__vector_score"
794
814
  ],
795
- SORTBY: "vector_score",
815
+ SORTBY: "__vector_score",
796
816
  DIALECT: 2,
797
817
  LIMIT: {
798
818
  from: 0,
@@ -802,11 +822,12 @@ var RedisDB = class {
802
822
  try {
803
823
  const results = await this.client.ft.search(
804
824
  this.indexName,
805
- `${filterExpr} =>[KNN ${limit} @embedding $vec AS vector_score]`,
825
+ `${filterExpr} =>[KNN ${limit} @embedding $vec AS __vector_score]`,
806
826
  searchOptions
807
827
  );
808
828
  return results.documents.map((doc) => {
809
- const payload = {
829
+ var _a;
830
+ const resultPayload = {
810
831
  hash: doc.value.hash,
811
832
  data: doc.value.memory,
812
833
  created_at: new Date(parseInt(doc.value.created_at)).toISOString(),
@@ -820,8 +841,8 @@ var RedisDB = class {
820
841
  };
821
842
  return {
822
843
  id: doc.value.memory_id,
823
- payload,
824
- score: doc.value.vector_score
844
+ payload: toCamelCase(resultPayload),
845
+ score: (_a = Number(doc.value.__vector_score)) != null ? _a : 0
825
846
  };
826
847
  });
827
848
  } catch (error) {
@@ -919,22 +940,23 @@ var RedisDB = class {
919
940
  }
920
941
  }
921
942
  async update(vectorId, vector, payload) {
943
+ const snakePayload = toSnakeCase(payload);
922
944
  const entry = {
923
945
  memory_id: vectorId,
924
- hash: payload.hash,
925
- memory: payload.data,
926
- created_at: new Date(payload.created_at).getTime(),
927
- updated_at: new Date(payload.updated_at).getTime(),
946
+ hash: snakePayload.hash,
947
+ memory: snakePayload.data,
948
+ created_at: new Date(snakePayload.created_at).getTime(),
949
+ updated_at: new Date(snakePayload.updated_at).getTime(),
928
950
  embedding: Buffer.from(new Float32Array(vector).buffer)
929
951
  };
930
952
  ["agent_id", "run_id", "user_id"].forEach((field) => {
931
- if (field in payload) {
932
- entry[field] = payload[field];
953
+ if (field in snakePayload) {
954
+ entry[field] = snakePayload[field];
933
955
  }
934
956
  });
935
957
  entry.metadata = JSON.stringify(
936
958
  Object.fromEntries(
937
- Object.entries(payload).filter(([key]) => !EXCLUDED_KEYS.has(key))
959
+ Object.entries(snakePayload).filter(([key]) => !EXCLUDED_KEYS.has(key))
938
960
  )
939
961
  );
940
962
  try {
@@ -966,7 +988,8 @@ var RedisDB = class {
966
988
  await this.client.ft.dropIndex(this.indexName);
967
989
  }
968
990
  async list(filters, limit = 100) {
969
- const filterExpr = filters ? Object.entries(filters).filter(([_, value]) => value !== null).map(([key, value]) => `@${key}:{${value}}`).join(" ") : "*";
991
+ const snakeFilters = filters ? toSnakeCase(filters) : void 0;
992
+ const filterExpr = snakeFilters ? Object.entries(snakeFilters).filter(([_, value]) => value !== null).map(([key, value]) => `@${key}:{${value}}`).join(" ") : "*";
970
993
  const searchOptions = {
971
994
  SORTBY: "created_at",
972
995
  SORTDIR: "DESC",
@@ -982,7 +1005,7 @@ var RedisDB = class {
982
1005
  );
983
1006
  const items = results.documents.map((doc) => ({
984
1007
  id: doc.value.memory_id,
985
- payload: {
1008
+ payload: toCamelCase({
986
1009
  hash: doc.value.hash,
987
1010
  data: doc.value.memory,
988
1011
  created_at: new Date(parseInt(doc.value.created_at)).toISOString(),
@@ -993,7 +1016,7 @@ var RedisDB = class {
993
1016
  ...doc.value.run_id && { run_id: doc.value.run_id },
994
1017
  ...doc.value.user_id && { user_id: doc.value.user_id },
995
1018
  ...JSON.parse(doc.value.metadata || "{}")
996
- }
1019
+ })
997
1020
  }));
998
1021
  return [items, results.total];
999
1022
  }