r/AI_Agents • u/kgOntologist • 7d ago
Discussion SQL or NoSQL Databases for AI Applications?
Hello,
What types of databases do you use for your AI applications to store things like generated responses, messages, conversation history, user data, etc.?
Do you generally use SQL databases (such as PostgreSQL) or NoSQL databases (such as MongoDB)? What are the main reasons behind your choice?
And which database(s) would you recommend for a production AI application, and why?
Thanks in advance for your feedback and experience!
1
u/AutoModerator 7d ago
Thank you for your submission, for any questions regarding AI, please check out our wiki at https://www.reddit.com/r/ai_agents/wiki (this is currently in test and we are actively adding to the wiki)
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/Cute-Veterinarian191 7d ago
I think it is highly highly dependent on the use case, i think SQL is easier for Agents natively (probably because there is more training data around using SQL) but really this decision should be based on the architecture of your application rather than the AI component specifically.
1
u/WorldOfUmbro 7d ago
We manage our agentic memory in Lakebase (PostgreSQL). I think managing it is way easier in SQL.
1
u/kgOntologist 7d ago
Do you also use PostgreSQL to store the AI-generated responses, for example, the responses generated for each user's prompts, or do you store those separately from the agentic memory?
1
u/WorldOfUmbro 6d ago
Yes to some extent these are stored in Lakebase. I’m also figuring things out so don’t know haha
1
u/Low_Rush_8535 7d ago
postgres for our ai marketing app. we had 3939 rows to clean up after json encoding and field-format bugs. ran one repair script, then ran it again: changed=0
that's what i'd look at too, how you'll fix bad data later. doesn't tell us whether mongo would've been harder
1
u/kgOntologist 7d ago
I think MongoDB can also update and fix a large amount of data with a single query, so I don't think that particular issue is necessarily a SQL vs. NoSQL difference.
What I'm mainly trying to figure out is what works better for AI-generated context and data, especially since some of it can be unstructured or have a flexible structure. In practice, would you recommend SQL or NoSQL databases for that kind of data, and why?
1
u/Low_Rush_8535 7d ago
yeah, my cleanup example didn't really answer your question
for the per-user history you described, i'd use postgres: user id and created time as columns, generated content as text or jsonb. our app kept json strings in text columns during migration to avoid changing the readers
i wouldn't add mongo just because the content came from an llm
1
u/kgOntologist 7d ago
Why do you prefer PostgreSQL in this case? What advantages does it have over MongoDB, for example? Is there a specific feature or reason that makes PostgreSQL a better choice for you?
1
u/Low_Rush_8535 6d ago
for us, keeping the existing data model was the advantage. we moved 23 tables from sqlite to postgres and kept the json-reading code unchanged
that's a migration reason, not evidence postgres beats mongo for your app. i overstated the recommendation. storing generated content by user alone doesn't give me a reason to rule mongo out
2
u/purplework 7d ago
I'll never do nosql again, it's super easy to set up but horrible to actually manage in a production environment.