Added Feedback in SDK (#2393)
This commit is contained in:
@@ -55,7 +55,8 @@
|
|||||||
"features/direct-import",
|
"features/direct-import",
|
||||||
"features/async-client",
|
"features/async-client",
|
||||||
"features/memory-export",
|
"features/memory-export",
|
||||||
"features/webhooks"
|
"features/webhooks",
|
||||||
|
"features/feedback-mechanism"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
62
docs/features/feedback-mechanism.mdx
Normal file
62
docs/features/feedback-mechanism.mdx
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
---
|
||||||
|
title: Feedback Mechanism
|
||||||
|
icon: "thumbs-up"
|
||||||
|
iconType: "solid"
|
||||||
|
---
|
||||||
|
|
||||||
|
Mem0's **Feedback Mechanism** allows you to provide feedback on the memories generated by your application. This feedback is used to improve the accuracy of the memories and the search results.
|
||||||
|
|
||||||
|
## How it works
|
||||||
|
|
||||||
|
The feedback mechanism is a simple API that allows you to provide feedback on the memories generated by your application. The feedback is stored in the database and is used to improve the accuracy of the memories and the search results. Over time, Mem0 continuously learns from this feedback, refining its memory generation and search capabilities for better performance.
|
||||||
|
|
||||||
|
## Give Feedback
|
||||||
|
|
||||||
|
You can give feedback on a memory by calling the `feedback` method on the Mem0 client.
|
||||||
|
|
||||||
|
<CodeGroup>
|
||||||
|
|
||||||
|
```python Python
|
||||||
|
from mem0 import Mem0
|
||||||
|
|
||||||
|
client = Mem0(api_key="your_api_key")
|
||||||
|
|
||||||
|
client.feedback(memory_id="your-memory-id", feedback="NEGATIVE", feedback_reason="I don't like this memory because it is not relevant.")
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript JavaScript
|
||||||
|
import MemoryClient from 'mem0ai';
|
||||||
|
|
||||||
|
const client = new MemoryClient({ apiKey: 'your-api-key'});
|
||||||
|
|
||||||
|
client.feedback({
|
||||||
|
memory_id: "your-memory-id",
|
||||||
|
feedback: "NEGATIVE",
|
||||||
|
feedback_reason: "I don't like this memory because it is not relevant."
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
</CodeGroup>
|
||||||
|
|
||||||
|
## Feedback Types
|
||||||
|
|
||||||
|
The `feedback` parameter can be one of the following values:
|
||||||
|
|
||||||
|
- `POSITIVE`: The memory is useful.
|
||||||
|
- `NEGATIVE`: The memory is not useful.
|
||||||
|
- `VERY_NEGATIVE`: The memory is not useful at all.
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
The `feedback` method takes the following parameters:
|
||||||
|
|
||||||
|
- `memory_id`: The ID of the memory to give feedback on.
|
||||||
|
- `feedback`: The feedback to give on the memory. (Optional)
|
||||||
|
- `feedback_reason`: The reason for the feedback. (Optional)
|
||||||
|
|
||||||
|
The `feedback_reason` parameter is optional and can be used to provide a reason for the feedback.
|
||||||
|
|
||||||
|
<Note>
|
||||||
|
You can pass `None` or `null` to the `feedback` and `feedback_reason` parameters to remove the feedback for a memory.
|
||||||
|
</Note>
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mem0ai",
|
"name": "mem0ai",
|
||||||
"version": "2.1.5",
|
"version": "2.1.8",
|
||||||
"description": "The Memory Layer For Your AI Apps",
|
"description": "The Memory Layer For Your AI Apps",
|
||||||
"main": "./dist/index.js",
|
"main": "./dist/index.js",
|
||||||
"module": "./dist/index.mjs",
|
"module": "./dist/index.mjs",
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ export type {
|
|||||||
Message,
|
Message,
|
||||||
AllUsers,
|
AllUsers,
|
||||||
User,
|
User,
|
||||||
|
FeedbackPayload,
|
||||||
|
Feedback,
|
||||||
} from "./mem0.types";
|
} from "./mem0.types";
|
||||||
|
|
||||||
// Export telemetry types
|
// Export telemetry types
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import {
|
|||||||
Webhook,
|
Webhook,
|
||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
Message,
|
Message,
|
||||||
|
FeedbackPayload,
|
||||||
} from "./mem0.types";
|
} from "./mem0.types";
|
||||||
import { captureClientEvent, generateHash } from "./telemetry";
|
import { captureClientEvent, generateHash } from "./telemetry";
|
||||||
|
|
||||||
@@ -560,6 +561,18 @@ export default class MemoryClient {
|
|||||||
);
|
);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async feedback(data: FeedbackPayload): Promise<{ message: string }> {
|
||||||
|
const response = await this._fetchWithErrorHandling(
|
||||||
|
`${this.host}/v1/feedback/`,
|
||||||
|
{
|
||||||
|
method: "POST",
|
||||||
|
headers: this.headers,
|
||||||
|
body: JSON.stringify(data),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export { MemoryClient };
|
export { MemoryClient };
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ export enum API_VERSION {
|
|||||||
V2 = "v2",
|
V2 = "v2",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum Feedback {
|
||||||
|
POSITIVE = "POSITIVE",
|
||||||
|
NEGATIVE = "NEGATIVE",
|
||||||
|
VERY_NEGATIVE = "VERY_NEGATIVE",
|
||||||
|
}
|
||||||
|
|
||||||
export interface MultiModalMessages {
|
export interface MultiModalMessages {
|
||||||
type: "image_url";
|
type: "image_url";
|
||||||
image_url: {
|
image_url: {
|
||||||
@@ -164,3 +170,9 @@ export interface WebhookPayload {
|
|||||||
name: string;
|
name: string;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FeedbackPayload {
|
||||||
|
memory_id: string;
|
||||||
|
feedback?: Feedback | null;
|
||||||
|
feedback_reason?: string | null;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import os
|
|||||||
import warnings
|
import warnings
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
from typing import Any, Dict, List, Optional, Union
|
from typing import Any, Dict, List, Optional, Union
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
@@ -998,3 +999,22 @@ class AsyncMemoryClient:
|
|||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
capture_client_event("async_client.delete_webhook", self.sync_client, {"webhook_id": webhook_id})
|
capture_client_event("async_client.delete_webhook", self.sync_client, {"webhook_id": webhook_id})
|
||||||
return response.json()
|
return response.json()
|
||||||
|
|
||||||
|
@api_error_handler
|
||||||
|
async def feedback(self, memory_id: str, feedback: Optional[str] = None, feedback_reason: Optional[str] = None) -> Dict[str, str]:
|
||||||
|
VALID_FEEDBACK_VALUES = {"POSITIVE", "NEGATIVE", "VERY_NEGATIVE"}
|
||||||
|
|
||||||
|
feedback = feedback.upper() if feedback else None
|
||||||
|
if feedback is not None and feedback not in VALID_FEEDBACK_VALUES:
|
||||||
|
raise ValueError(f'feedback must be one of {", ".join(VALID_FEEDBACK_VALUES)} or None')
|
||||||
|
|
||||||
|
data = {
|
||||||
|
"memory_id": memory_id,
|
||||||
|
"feedback": feedback,
|
||||||
|
"feedback_reason": feedback_reason
|
||||||
|
}
|
||||||
|
|
||||||
|
response = await self.async_client.post("/v1/feedback/", json=data)
|
||||||
|
response.raise_for_status()
|
||||||
|
capture_client_event("async_client.feedback", self.sync_client, data)
|
||||||
|
return response.json()
|
||||||
Reference in New Issue
Block a user