mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
22.68k stars 2.09k forks source link

[feat]: Custom categories added #1894

Open spike-spiegel-21 opened 1 month ago

spike-spiegel-21 commented 1 month ago

Potential fix: #1863 Feature replicating: https://docs.mem0.ai/features/custom-categories

Could be tested using: Filter: "restrict"

# Initialize Memory with the configuration
m = Memory.from_config(config)

custom_categories = {
    "categories" : [
        {"financial": "Includes content related to personal finance, investing strategies, saving tips, market trends, and financial planning."},
        {"programming": "For users interested in programming, including tutorials, coding tips, language-specific content, and software development best practices."}
    ], 
    "filter": "restrict"
}
m.add("Alice enjoys hiking, favors using Python for backend development, and prefers budgeting apps to manage her finances.", user_id="alice1", custom_categories=custom_categories)
m.add("Alice is passionate about front-end development with React and spends her weekends exploring new restaurants.", user_id="alice1", custom_categories=custom_categories)
m.add("Alice loves reading historical fiction, excels in writing efficient Python scripts, and is an avid traveler.", user_id="alice1", custom_categories=custom_categories)
m.add("Alice is a fan of indie films and enjoys practicing yoga.", user_id="alice1", custom_categories=custom_categories)
memories=m.get_all(user_id="alice1")

Output:

#memories
Passionate about front-end development with React
Alice excels in writing efficient Python scripts
Prefers budgeting apps to manage her finances
Name is Alice
Favors using Python for backend development

Filter: "omit"

custom_categories = {
    "categories" : [
        {"financial": "Includes content related to personal finance, investing strategies, saving tips, market trends, and financial planning."},
        {"programming": "For users interested in programming, including tutorials, coding tips, language-specific content, and software development best practices."}
    ], 
    "filter": "omit"
}
m.add("Alice enjoys hiking, favors using Python for backend development, and prefers budgeting apps to manage her finances.", user_id="alice3", custom_categories=custom_categories)
m.add("Alice is passionate about front-end development with React and spends her weekends exploring new restaurants.", user_id="alice3", custom_categories=custom_categories)
m.add("Alice loves reading historical fiction, excels in writing efficient Python scripts, and is an avid traveler.", user_id="alice3", custom_categories=custom_categories)
m.add("Alice is a fan of indie films and enjoys practicing yoga.", user_id="alice3", custom_categories=custom_categories)
memories=m.get_all(user_id="alice3")

Output

#memories
Alice is passionate about front-end development with React
Alice loves reading historical fiction
Alice is an avid traveler
Alice is a fan of indie films
Alice enjoys practicing yoga
Alice spends her weekends exploring new restaurants
Alice enjoys hiking

Filter: "extend"

custom_categories = {
    "categories" : [
        {"financial": "Includes content related to personal finance, investing strategies, saving tips, market trends, and financial planning."},
        {"programming": "For users interested in programming, including tutorials, coding tips, language-specific content, and software development best practices."}
    ], 
    "filter": "extend"
}
m.add("Alice enjoys hiking, favors using Python for backend development, and prefers budgeting apps to manage her finances.", user_id="alice1", custom_categories=custom_categories)
m.add("Alice is passionate about front-end development with React and spends her weekends exploring new restaurants.", user_id="alice1", custom_categories=custom_categories)
m.add("Alice loves reading historical fiction, excels in writing efficient Python scripts, and is an avid traveler.", user_id="alice1", custom_category=custom_categories=custom_categories)
m.add("Alice is a fan of indie films and enjoys practicing yoga.", user_id="alice1", custom_categories=custom_categories)

Output:

Alice excels in writing efficient Python scripts
Alice spends her weekends exploring new restaurants
Alice favors using Python for backend development
Alice is a fan of indie films
Alice is passionate about front-end development with React
Alice enjoys practicing yoga
Alice enjoys hiking
Alice loves reading historical fiction
Alice prefers budgeting apps to manage her finances
Alice is an avid traveler
spike-spiegel-21 commented 1 month ago

Hi @Dev-Khant Let me know if I want to change prompt or add something.

spike-spiegel-21 commented 1 month ago

Hi @deshraj @prateekchhikara Let me know if we need any improvements. Will work on TCs post finalisations of prompts and flow.

spike-spiegel-21 commented 1 month ago

Hi @deshraj @prateekchhikara, I have done the validation using pydantic for CustomCategories. The changes seems better. Please review. Thanks