I am making an app that generates recipes with AI. I want to generate these recipes by, first, elaborating a full step-by-step recipe with a propmpt and then creating an image of that recipe with another propmt.
The problem I am facing is that I do not know how to save all the recipes generated in my database without saving duplicated recipes.
In other words, the AI can generate similar or identical recipes if I pass it a list of the same ingredients. I want to prevent duplicate recipes from being saved in the database. How could I do that?
Hi @Oscar_Baeza Welcome to the community!
The duplicity issue has many solutions depending on the kind of database you are using, what i would recommend is that whatever database you are using just generate a hash using crypto node of every data which will be stored along the data something like UUID and just compare that hash before inserting anything into the database that if this hash already exists nothing would be written else the row would be appended.
The hash approach is solid but honestly for recipe deduplication you might want something fuzzier since AI won’t generate byte-for-byte identical text even for the same dish. Before inserting, you could have another AI call that takes the new recipe title/ingredients and asks “is this essentially the same as any of these existing recipes?” and pass it your recent recipes from the database. If your database supports it you could also look into vector similarity search which would catch things like “Chicken Stir Fry” vs “Stir-Fried Chicken” that a hash would miss completely.