Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SQLite for custom data layer #832

Closed
wants to merge 6 commits into from
Closed

Conversation

tjroamer
Copy link

@tjroamer tjroamer commented Mar 20, 2024

Overview

How to configure

import chainlit.data as cl_data
from chainlit.data.sqlite import SQLiteDataLayer

# a default database file chainlit.db will be created in the working dir
cl_data._data_layer = SQLiteDataLayer()

# Or optionally provide own file (can be relative or absolute) as the init parameter
# this code will create C:/myfolder if it doesn't exist, and data is persited in mydata.db
cl_data._data_layer = SQLiteDataLayer(db_filepath="C:/myfolder/mydata.db")

Test

A simple sanity check is implemented in cypress/e2e/data_layer_sqlite, which is a simplified copy of cypress/e2e/data_layer.

Limitation

no file blob support, so chat history will not show attachments

@Rajatkhanna801
Copy link

Hi @tjroamer
I want to know If I want to create separate sqlite database for each user how I can do that.

@tjroamer
Copy link
Author

Hi @tjroamer I want to know If I want to create separate sqlite database for each user how I can do that.

With the current chainlit data layer, user-specific sqlite database might not be straightforward to implement. One solution I can think of is that you create views for different users, and select only rows that relevant to that user. This would require some post-processing steps once you have the database as a single file.

@Rajatkhanna801
Copy link

@tjroamer
Actually as per my requirement I want separate sqlite database for each user and I think we can achieve that with sending custom database url.

@tjroamer
Copy link
Author

Will these users use the same chatbot based on the same server? If this is the case, you cannot send custom database url for each user, since the database url is a server-side setting, and it is done only once when the server starts.

@Rajatkhanna801
Copy link

okay let me figure another way for that.

@Rajatkhanna801
Copy link

@tjroamer
I have configured Microsoft authentication and everytime new user logged in I am creating new database sqlite file.

But I am not sure how I can put data in that tables for specific user.

Kai Liu added 3 commits March 20, 2024 20:55
- hide the protocol sqlite+aiosqlite:/// under the hood
- user can use relative or absolute file path as input
@intc-hharshtk
Copy link

I just see this when I load old thread How to fix it
image

@LOFWagner
Copy link

Any Idea on when this will be merged?

@qtangs
Copy link
Contributor

qtangs commented Aug 10, 2024

I'm working on a new version of SQLAlchemyDataLayer so that it can support SQLite and other dialects. Will share it once I've done testing.

@dokterbob dokterbob added the data layer Pertains to data layers. label Aug 14, 2024
@dokterbob dokterbob added the enhancement New feature or request label Sep 3, 2024
@dokterbob
Copy link
Collaborator

I just went quite deep into the existing SQLAlchemy layer as part of #1319, added tests and make it work with SQLite.

I then read the code in this PR and realised I wished it wasn't called SQLite; I don't think we need an SQLite-specific layer, we can suffice with using SQLAlchemy, but the code in this PR (and possibly what's lying in @qtangs's attic) has a lot of good stuff I'd love to merge.

All of this towards a much needed cleanup on the roadmap to moving all non-literalai (after all, it's the core product!) data layers into a separate community-maintained repo.

I'd invite you all to have a look at #1319 and am also inviting you to share ideas on a community repo and how we could best pull that off (I'm thinking to invite 2/3 community members and setup a monorepo, with data layers first - but only after having test coverage for data layers).

@dokterbob
Copy link
Collaborator

#1319 has just been merged, we now have test coverage for SQLAlchemy/SQLite.

Looking forward to integrate the goodies from here!

@tjroamer Feel like giving this a try? Note that you've shot this PR from your own main branch, might want to continue working in a feature branch (e.g. with a different name).

@qtangs
Copy link
Contributor

qtangs commented Sep 22, 2024

I then read the code in this PR and realised I wished it wasn't called SQLite; I don't think we need an SQLite-specific layer, we can suffice with using SQLAlchemy, but the code in this PR (and possibly what's lying in @qtangs's attic) has a lot of good stuff I'd love to merge.

@dokterbob you're spot on. I've been building on top of the code here while integrating with SQLAlchemy. It has taken a while to rewrite everything and to test properly. Thanks for the reminder here.
I'm going to push the code as a draft PR for now while still not happy with it yet. But it's better to put it out there for the community to evaluate and correct. Hope this helps :)

@dokterbob
Copy link
Collaborator

Closing in favour of #1365.

@dokterbob dokterbob closed this Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data layer Pertains to data layers. enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants