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

Mark tiktoken functions as IMMUTABLE by default #8

Open
nick-inkeep opened this issue Jan 5, 2025 · 0 comments
Open

Mark tiktoken functions as IMMUTABLE by default #8

nick-inkeep opened this issue Jan 5, 2025 · 0 comments

Comments

@nick-inkeep
Copy link

Description

When using tiktoken_count in a generated column on managed Postgres instances (like Neon), we encounter:

ERROR: generation expression is not immutable

Since tokenization is deterministic (same input → same output), marking these functions as IMMUTABLE in the extension itself would allow direct use in generated columns without requiring superuser privileges.

Example Use Case

CREATE TABLE documents (
    content text NOT NULL,
    token_count integer GENERATED ALWAYS AS (tiktoken_count('cl100k_base', content)) STORED
);

Benefits

  • Works out of the box on managed Postgres instances
  • Enables use in generated columns
  • Follows Postgres best practices for deterministic functions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant