From 18d069d10c8b863c7c003a970e2b369d42528363 Mon Sep 17 00:00:00 2001 From: Dev Khant Date: Wed, 4 Sep 2024 22:51:32 +0530 Subject: [PATCH] Improve api reference for v2 search api (#1808) --- .../memory/v2-search-memories.mdx | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/docs/api-reference/memory/v2-search-memories.mdx b/docs/api-reference/memory/v2-search-memories.mdx index 5c591d66..0c340399 100644 --- a/docs/api-reference/memory/v2-search-memories.mdx +++ b/docs/api-reference/memory/v2-search-memories.mdx @@ -1,4 +1,84 @@ --- title: 'V2 Search Memories' openapi: post /v2/memories/search/ ---- \ No newline at end of file +--- + +Mem0 offers two versions of the search API: v1 and v2. Here's how they differ: + + + + + ```python Code + related_memories = m.search(query="What are Alice's hobbies?", user_id="alice") + ``` + + ```json Output + [ + { + "id":"ea925981-272f-40dd-b576-be64e4871429", + "memory":"Likes to play cricket and plays cricket on weekends.", + "hash":"c8809002-25c1-4c97-a3a2-227ce9c20c53", + "metadata":{ + "category":"hobbies" + }, + "score":0.32116443111457704, + "created_at":"2024-07-26T10:29:36.630547-07:00", + "updated_at":"None", + "user_id":"alice" + } + ] + ``` + + + + + + ```python Code + related_memories = m.v2_search( + query="What are Alice's hobbies?", + filters={ + "AND":[ + { + "user_id":"alice" + }, + { + "agent_id":{ + "in":[ + "travelling", + "sports" + ] + } + } + ] + } + ) + ``` + + ```json Output + { + "memories": [ + { + "id": "ea925981-272f-40dd-b576-be64e4871429", + "memory": "Likes to play cricket and plays cricket on weekends.", + "hash": "c8809002-25c1-4c97-a3a2-227ce9c20c53", + "metadata": { + "category": "hobbies" + }, + "score": 0.32116443111457704, + "created_at": "2024-07-26T10:29:36.630547-07:00", + "updated_at": null, + "user_id": "alice", + "agent_id": "sports" + } + ], + } + ``` + + + + +Key difference between v1 and v2 search: + +• **Filters**: v2 allows you to apply filters to narrow down search results based on specific criteria. This includes support for complex logical operations (AND, OR) and comparison operators (IN, gte, lte, gt, lt, ne, icontains) for advanced filtering capabilities. + +The v2 search API is more powerful and flexible, allowing for more precise memory retrieval.