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

refactor: sqlite3 proof of concept #2740

Merged
merged 12 commits into from
Apr 2, 2024
Merged

refactor: sqlite3 proof of concept #2740

merged 12 commits into from
Apr 2, 2024

Conversation

RogerHYang
Copy link
Contributor

No description provided.

@dosubot dosubot bot added the size:XL This PR changes 500-999 lines, ignoring generated files. label Apr 1, 2024
Comment on lines +12 to +18
_CONFIG = """
PRAGMA foreign_keys = ON;
PRAGMA journal_mode = WAL;
PRAGMA synchronous = OFF;
PRAGMA cache_size = -32000;
PRAGMA busy_timeout = 10000;
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note to self: need to figure out how this configuration is settable in something like sql alchemy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
from phoenix.core.model_schema_adapter import create_model_from_datasets
from phoenix.core.traces import Traces
from phoenix.datasets.dataset import EMPTY_DATASET, Dataset
from phoenix.datasets.fixtures import FIXTURES, get_datasets
from phoenix.db.database import SqliteDatabase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just phoenix.database?

_INIT_DB = """
BEGIN;
CREATE TABLE projects (
rowid INTEGER PRIMARY KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do index names usually not include underscores? Looks kind of weird.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rowid is from sqlite by default (https://www.sqlite.org/rowidtable.html), but i had to spell it out otherwise the foreign key constraint doesn't work. We can also name it something else, but I just left it as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a super nit but it might make sense to have this not be sqlite flavor. It's not a big deal but this is something that an ORM abstraction could abstract away. Let's see if we can.

Comment on lines 279 to 282
elif start_time:
cur = cur.execute(query + " AND ? <= spans.start_time;", (project_name, start_time))
elif start_time:
cur = cur.execute(query + " AND spans.start_time < ?;", (project_name, stop_time))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same condition twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

Copy link
Contributor

@mikeldking mikeldking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving to move on to the next phase. Still WIP

);
CREATE INDEX idx_trace_start_time ON traces(start_time);
CREATE TABLE spans (
rowid INTEGER PRIMARY KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rowid INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think when we move to sql alchamy we consider moving this to a simpler convention, though I get the confusing nature of the foreign keys....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll revise the names and incorporate the other feedbacks in the sqlalchemy edition of the schema

);
INSERT INTO projects(name) VALUES('default');
CREATE TABLE traces (
rowid INTEGER PRIMARY KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rowid INTEGER PRIMARY KEY,
id INTEGER PRIMARY KEY,

_INIT_DB = """
BEGIN;
CREATE TABLE projects (
rowid INTEGER PRIMARY KEY,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a super nit but it might make sense to have this not be sqlite flavor. It's not a big deal but this is something that an ORM abstraction could abstract away. Let's see if we can.

Comment on lines +120 to +126
cumulative_error_count = int(span.status_code is SpanStatusCode.ERROR)
cumulative_llm_token_count_prompt = cast(
int, span.attributes.get(SpanAttributes.LLM_TOKEN_COUNT_PROMPT, 0)
)
cumulative_llm_token_count_completion = cast(
int, span.attributes.get(SpanAttributes.LLM_TOKEN_COUNT_COMPLETION, 0)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think about keeping the DB layer clean

Comment on lines +334 to +337
cumulative_error_count=span[11],
cumulative_llm_token_count_prompt=span[12],
cumulative_llm_token_count_completion=span[13],
cumulative_llm_token_count_total=span[12] + span[13],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed that maybe dynamic "computed columns" might belong separate to the span.

@RogerHYang
Copy link
Contributor Author

Merging for now, but I'll revise the names and incorporate the other feedbacks in the sqlalchemy edition of the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants