Skip to content

Commit a10c86f

Browse files
authored
feat(halfvec): support halfvec for postgres target (#1171)
* feat(postgres): allow to put SQL type in target states * feat(halfvec): support `halfvec` for postgres target
1 parent 844739e commit a10c86f

File tree

5 files changed

+239
-53
lines changed

5 files changed

+239
-53
lines changed

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ tower = "0.5.2"
6161
tower-http = { version = "0.6.6", features = ["cors", "trace"] }
6262
indexmap = { version = "2.10.0", features = ["serde"] }
6363
blake2 = "0.10.6"
64-
pgvector = { version = "0.4.1", features = ["sqlx"] }
64+
pgvector = { version = "0.4.1", features = ["sqlx", "halfvec"] }
6565
phf = { version = "0.12.1", features = ["macros"] }
6666
indenter = "0.3.4"
6767
itertools = "0.14.0"

docs/docs/targets/postgres.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ The spec takes the following fields:
4949

5050
* `schema` (`str`, optional): The PostgreSQL schema to create the table in. If unspecified, the table will be created in the default schema (usually `public`). When specified, `table_name` must also be explicitly specified. CocoIndex will automatically create the schema if it doesn't exist.
5151

52+
* `column_options` (`dict[str, PostgresColumnOptions]`, optional): Options for the columns in the table.
53+
Key is the column name, and value is the specific option, with the following fields:
54+
55+
* `type` (`str`, optional): The specific type of the column in Postgres. Currently only supports `"vector"` and `"halfvec"`. By default, we use `"vector"` for vector columns, and you can use this field to override it to `"halfvec"` for some columns.
56+
5257
## Attachments
5358

5459
### PostgresSqlCommand

python/cocoindex/targets/_engine_builtin_specs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
"""All builtin targets."""
22

33
from dataclasses import dataclass
4-
from typing import Sequence
4+
from typing import Sequence, Literal
55

66
from .. import op
77
from .. import index
88
from ..auth_registry import AuthEntryReference
99
from ..setting import DatabaseConnectionSpec
1010

1111

12+
@dataclass
13+
class PostgresColumnOptions:
14+
"""Options for a Postgres column."""
15+
16+
# Specify the specific type of the column in Postgres. Can use it to override the default type derived from CocoIndex schema.
17+
type: Literal["vector", "halfvec"] | None = None
18+
19+
1220
class Postgres(op.TargetSpec):
1321
"""Target powered by Postgres and pgvector."""
1422

1523
database: AuthEntryReference[DatabaseConnectionSpec] | None = None
1624
table_name: str | None = None
1725
schema: str | None = None
26+
column_options: dict[str, PostgresColumnOptions] | None = None
1827

1928

2029
class PostgresSqlCommand(op.TargetAttachmentSpec):

0 commit comments

Comments
 (0)