Skip to content

PGVector support #11485

Open
Open

Description

@naorpeled

Hey :)

I've started working on adding pgvector support to TypeORM.

My initial goal is to cover the following data types.

I've started with Vector here.
Let me know if you want to take any of the other data types :)

Activity

  1. Danbaba1 commented on May 26, 2025

    @Danbaba1

    I will take Halfvec

  2. naorpeled commented on May 26, 2025

    @naorpeled
    MemberAuthor

    I will take Halfvec

    Amazing! Let me know if you need any assistance

  3. Danbaba1 commented on May 27, 2025

    @Danbaba1

    I will take Halfvec

    Amazing! Let me know if you need any assistance

    Okay I will. Thank you

  4. GuillaumeMunsch commented on Aug 27, 2025

    @GuillaumeMunsch

    Hey,

    Do you guys have any visibility on this? 🙏

  5. vihardesu commented on Sep 11, 2025

    @vihardesu

    is this ready??

  6. naorpeled commented on Sep 13, 2025

    @naorpeled
    MemberAuthor

    Hey @Danbaba1,
    as part of my vector PR, I'm already adding halfvec.

    Let me know if you'd like to take any other data type 🙏

  7. naorpeled commented on Sep 13, 2025

    @naorpeled
    MemberAuthor

    Hey,

    Do you guys have any visibility on this? 🙏

    Yes, this PR.
    I'm currently finalizing it, hoping to get it merged in the next few days.

  8. naorpeled commented on Sep 13, 2025

    @naorpeled
    MemberAuthor

    is this ready??

    Almost done 🙏

  9. i-tengfei commented on Nov 1, 2025

    @i-tengfei

    Index support? like:

    CREATE INDEX IF NOT EXISTS x ON xx USING hnsw (embedding vector_cosine_ops) WITH (ef_construction = 300, m = 16);
    
  10. naorpeled commented on Nov 22, 2025

    @naorpeled
    MemberAuthor

    Index support? like:

    CREATE INDEX IF NOT EXISTS x ON xx USING hnsw (embedding vector_cosine_ops) WITH (ef_construction = 300, m = 16);
    

    I'll raise this topic in the next maintainers meeting and keep you posted 🙏

  11. naorpeled commented on Nov 22, 2025

    @naorpeled
    MemberAuthor

    Both Vector and Halfvec were added in v0.3.27 😎

  12. Cprakhar commented on Jan 13, 2026

    @Cprakhar
    Collaborator

    @naorpeled I have created a draft for Bit and Sparsevec. I would appreciate your review.

  13. kyungseopk1m commented on Mar 29, 2026

    @kyungseopk1m
    Contributor

    Hi @naorpeled, I'd like to work on the remaining Bit and Sparsevec types. I'll reference the existing Vector/Halfvec PR (#11437) for the implementation pattern. Let me know if there's anything I should keep in mind.

  14. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one (PGVector support). I'll look into the root cause and follow up with a PR. (claiming via @LeonxLJX)

  15. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one (PGVector support). I'll look into the root cause and follow up with a PR. (claiming via @LeonxLJX)

  16. LeonxLJX commented on Sep 1, 2026

    @LeonxLJX

    I'd like to take this one (PGVector support). I'll dig into the root cause and follow up with a PR shortly. (claiming via @LeonxLJX)

  17. aneesahmed330 commented on Nov 26, 2026

    @aneesahmed330

    Hi @naorpeled 👋 Following up on the index question above (HNSW / IVFFlat), since vector and halfvec landed in 0.3.27 and bit/sparsevec are in progress. I'd like to implement it and want to check the API shape with you first.

    Why it needs more than a new type: pgvector defines no default operator class for hnsw (and for ivfflat only vector_l2_ops is the default), so USING hnsw ("embedding") fails, and cosine/inner-product indexes always need an explicit opclass. The operator class (vector_cosine_ops, vector_l2_ops, halfvec_ip_ops, …) and the build parameters (m, ef_construction, lists) both have to be expressible.

    Proposed API (extends the existing type option):

    @Index({
        type: "hnsw",                        // new: "hnsw" | "ivfflat" added to TableIndexTypes (postgres only)
        operatorClass: "vector_cosine_ops",  // new: appended after the column(s)
        with: { m: 16, ef_construction: 64 } // new: rendered as WITH (m = 16, ef_construction = 64)
    })
    @Column({ type: "vector", length: 1536 })
    embedding: number[]

    Generated SQL:

    CREATE INDEX "IDX_…" ON "post" USING hnsw ("embedding" vector_cosine_ops) WITH (m = 16, ef_construction = 64)

    Plan:

    1. TableIndexTypes + PostgresDriver.supportedIndexTypes: add hnsw, ivfflat
    2. IndexOptions / IndexMetadata / TableIndex: add operatorClass?: string and with?: Record<string, number | string | boolean>
    3. PostgresQueryRunner.createIndexSql() (+ view variant): emit the opclass after the columns and a WITH (…) clause
    4. Schema loading: read the opclass (pg_index.indclass → pg_opclass.opcname) and pg_class.reloptions, and include both in index comparison, so migration:generate doesn't drop and recreate the index on every run
    5. Tests: extend test/functional/indices/index-types with hnsw + ivfflat entities (the pgvector image is already in docker-compose), plus a migration-diff test showing no changes on the second run. Docs in the indices page.

    Open questions:

    • Naming: operatorClass + with, or something closer to existing options (e.g. opclass, storageParameters)?
    • Would you prefer one PR, or splitting create-SQL (1–3) from introspection/diff (4)?

    Happy to adjust. If this looks right, I'll open a draft PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions