pg_tiktoken
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_tiktoken | 0.0.1 | RAG | Apache-2.0 | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1870 | pg_tiktoken | No | Yes | No | Yes | No | No | - |
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.1 | 1817161514 | pg_tiktoken | - |
| RPM | PIGSTY | 0.0.1 | 1817161514 | pg_tiktoken_$v | - |
| DEB | PIGSTY | 0.0.1 | 1817161514 | postgresql-$v-pg-tiktoken | - |
Build
You can build the RPM / DEB packages for pg_tiktoken using pig build:
Install
You can install pg_tiktoken directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:
Install the extension using pig or apt/yum/dnf:
Create Extension:
Usage
pg_tiktoken: tiktoken tokenizer for use with OpenAI models in PostgreSQL. Source: README.md
pg_tiktoken is a PostgreSQL extension that provides input tokenization using OpenAI’s tiktoken library. It allows you to count and encode tokens directly in SQL, which is useful for managing input length limits when working with OpenAI models.
Functions
tiktoken_count
Count the number of tokens for a given encoding or model:
tiktoken_encode
Get the token IDs for a given encoding or model:
Both tiktoken_count and tiktoken_encode accept either an encoding name or an OpenAI model name as the first argument.
Supported Models
| Encoding name | OpenAI models |
|---|---|
cl100k_base | ChatGPT models, text-embedding-ada-002 |
p50k_base | Code models, text-davinci-002, text-davinci-003 |
p50k_edit | Edit models like text-davinci-edit-001, code-davinci-edit-001 |
r50k_base (or gpt2) | GPT-3 models like davinci |
Was this page helpful?
Thanks—your feedback helps us improve this page.
What got in the way? (optional)