Skip to content

feat(pgvector): add cosineSimilarity operation#271

Merged
aqrln merged 1 commit into
mainfrom
aqrln-qvsylnyzyxrs
Mar 31, 2026
Merged

feat(pgvector): add cosineSimilarity operation#271
aqrln merged 1 commit into
mainfrom
aqrln-qvsylnyzyxrs

Conversation

@aqrln
Copy link
Copy Markdown
Member

@aqrln aqrln commented Mar 31, 2026

Follow up to #270.

Add a separate cosineSimilarity operation with 1 - ({{self}} <=> {{arg0}}) lowering because it is also useful.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added cosineSimilarity operation for pgvector extension, enabling vector similarity calculations computed as 1 minus cosine distance, with results ranging from 0 to 1.
  • Documentation

    • Updated pgvector README with cosineSimilarity operation documentation, including TypeScript signatures and SQL rendering examples.
  • Tests

    • Added integration tests validating cosineSimilarity operation behavior and query results.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 31, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 66dfa74d-6d08-41cd-987e-67d333f7b366

📥 Commits

Reviewing files that changed from the base of the PR and between e365e2b and 7fc9d6f.

📒 Files selected for processing (11)
  • packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts
  • packages/3-extensions/pgvector/README.md
  • packages/3-extensions/pgvector/src/core/descriptor-meta.ts
  • packages/3-extensions/pgvector/src/exports/control.ts
  • packages/3-extensions/pgvector/src/exports/runtime.ts
  • packages/3-extensions/pgvector/src/types/operation-types.ts
  • packages/3-extensions/pgvector/test/manifest.test.ts
  • packages/3-extensions/pgvector/test/operations.test.ts
  • packages/3-extensions/pgvector/test/result-type.types.test-d.ts
  • test/integration/test/pgvector.test.ts
  • test/utils/src/operation-descriptors.ts
✅ Files skipped from review due to trivial changes (6)
  • packages/3-extensions/pgvector/test/result-type.types.test-d.ts
  • packages/3-extensions/pgvector/src/exports/control.ts
  • packages/3-extensions/pgvector/src/types/operation-types.ts
  • test/integration/test/pgvector.test.ts
  • packages/3-extensions/pgvector/src/exports/runtime.ts
  • packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts
🚧 Files skipped from review as they are similar to previous changes (5)
  • test/utils/src/operation-descriptors.ts
  • packages/3-extensions/pgvector/README.md
  • packages/3-extensions/pgvector/test/manifest.test.ts
  • packages/3-extensions/pgvector/test/operations.test.ts
  • packages/3-extensions/pgvector/src/core/descriptor-meta.ts

📝 Walkthrough

Walkthrough

Added support for a new cosineSimilarity operation to the pgvector PostgreSQL extension. The operation calculates similarity as one minus cosine distance. Updated descriptors, type definitions, operation registries, documentation, and test suites to include the new operation alongside the existing cosineDistance operation.

Changes

Cohort / File(s) Summary
pgvector Core Definitions
packages/3-extensions/pgvector/src/core/descriptor-meta.ts, packages/3-extensions/pgvector/src/types/operation-types.ts
Added cosineSimilarity operation descriptor and type definition. Changed from single pgvectorOperationSignature to plural pgvectorOperationSignatures array containing both cosineDistance and cosineSimilarity with distinct SQL lowering templates ({{self}} <=> {{arg0}} vs. 1 - ({{self}} <=> {{arg0}})). Extended QueryOperationTypes and pgvectorQueryOperations.
pgvector Exports
packages/3-extensions/pgvector/src/exports/control.ts, packages/3-extensions/pgvector/src/exports/runtime.ts
Updated imports and descriptor callbacks to use pgvectorOperationSignatures (plural) instead of wrapping single pgvectorOperationSignature in an array.
Documentation
packages/3-extensions/pgvector/README.md
Added cosineSimilarity operation documentation including type signature, semantics ("1 minus cosine distance"), SQL rendering template, and usage example. Updated OperationTypes exported type mapping.
pgvector Manifest & Operations Tests
packages/3-extensions/pgvector/test/manifest.test.ts, packages/3-extensions/pgvector/test/operations.test.ts
Tightened expected operation count from "greater than 0" to exactly 2. Added assertions verifying cosineSimilarity operation presence, shape, and SQL lowering template. Updated registry tests to verify both operations exist.
Type & Integration Tests
packages/3-extensions/pgvector/test/result-type.types.test-d.ts, test/integration/test/pgvector.test.ts
Added type-level test for cosineSimilarity result inference. Updated integration tests to verify both operation signatures and replaced positional indexing with find(...) lookups.
SQL Builder & Test Utils
packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts, test/utils/src/operation-descriptors.ts
Added integration tests querying cosineSimilarity with vector parameters and WHERE predicates. Added cosineSimilarity operation descriptor to test utilities with matching signature and lowering template.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A vector so fine, two operations now shine,
Distance and similarity, both by design!
One minus the other, a clever new measure,
Cosines aligned bring semantic pleasure! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a new cosineSimilarity operation to the pgvector extension, which is the primary focus of the changeset across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch aqrln-qvsylnyzyxrs

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Mar 31, 2026

Open in StackBlitz

@prisma-next/runtime-executor

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/runtime-executor@271

@prisma-next/mongo-core

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-core@271

@prisma-next/mongo-orm

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-orm@271

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/mongo-runtime@271

@prisma-next/sql-runtime

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-runtime@271

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-paradedb@271

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/extension-pgvector@271

@prisma-next/postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/postgres@271

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-orm-client@271

@prisma-next/target-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-mongo@271

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-mongo@271

@prisma-next/driver-mongo

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-mongo@271

@prisma-next/contract-authoring

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract-authoring@271

@prisma-next/contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract-ts@271

@prisma-next/ids

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/ids@271

@prisma-next/psl-parser

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-parser@271

@prisma-next/psl-printer

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/psl-printer@271

@prisma-next/cli

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/cli@271

@prisma-next/emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/emitter@271

@prisma-next/eslint-plugin

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/eslint-plugin@271

@prisma-next/migration-tools

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/migration-tools@271

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/vite-plugin-contract-emit@271

@prisma-next/sql-contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract@271

@prisma-next/sql-errors

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-errors@271

@prisma-next/sql-operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-operations@271

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-schema-ir@271

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-psl@271

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-ts@271

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-contract-emitter@271

@prisma-next/family-sql

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/family-sql@271

@prisma-next/sql-kysely-lane

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-kysely-lane@271

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-lane-query-builder@271

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-relational-core@271

@prisma-next/sql-builder-new

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-builder-new@271

@prisma-next/sql-lane

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/sql-lane@271

@prisma-next/target-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/target-postgres@271

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/adapter-postgres@271

@prisma-next/driver-postgres

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/driver-postgres@271

@prisma-next/core-control-plane

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/core-control-plane@271

@prisma-next/core-execution-plane

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/core-execution-plane@271

@prisma-next/config

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/config@271

@prisma-next/contract

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/contract@271

@prisma-next/operations

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/operations@271

@prisma-next/plan

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/plan@271

@prisma-next/utils

npm i https://pkg.pr.new/prisma/prisma-next/@prisma-next/utils@271

commit: 7fc9d6f

@aqrln aqrln marked this pull request as ready for review March 31, 2026 14:07
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
packages/3-extensions/pgvector/test/result-type.types.test-d.ts (1)

321-325: Add an explicit expectTypeOf assertion for Row['similarity'].

The current assignment check works, but a direct type assertion will better protect against accidental widening (any/unknown) regressions.

♻️ Suggested type assertion
   type Row = ResultType<typeof _plan>;
   const similarityValue = 0 as Row['similarity'];
   const similarityAsExpected: number = similarityValue;
   void similarityAsExpected;
+  expectTypeOf({} as Row).toExtend<{ similarity: number }>();
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/3-extensions/pgvector/test/result-type.types.test-d.ts` around lines
321 - 325, The test currently infers Row via ResultType<typeof _plan> and checks
assignment to number indirectly; add an explicit expectTypeOf assertion for
Row['similarity'] to lock its static type to number. Locate the
Row/ResultType/_plan usage in the test and add an expectTypeOf assertion that
compares Row['similarity'] to number (e.g.,
expectTypeOf<Row['similarity']>().toEqualTypeOf<number>()) so the type cannot
widen to any/unknown.
packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts (1)

42-53: Strengthen the WHERE-filter test with an explicit negative assertion.

Right now the test only proves inclusion of id=1. Adding an exclusion check (e.g., orthogonal row) makes regressions easier to catch.

♻️ Suggested test hardening
   expect(rows.length).toBeGreaterThan(0);
   expect(rows.some((r) => r.id === 1)).toBe(true);
+  expect(rows.some((r) => r.id === 3)).toBe(false);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts`
around lines 42 - 53, The test "cosineSimilarity filters in WHERE" only asserts
presence of the matching row (id === 1) and should also assert exclusion of an
orthogonal row to catch regressions; update the test that calls
db().posts.select('id').where((f, fns) =>
fns.gt(fns.cosineSimilarity(f.embedding, [1, 0, 0]), 0.5)).all() to include an
explicit negative assertion such as expect(rows.some(r => r.id ===
3)).toBe(false) (or equivalent) so the orthogonal embedding is confirmed
filtered out.
packages/3-extensions/pgvector/src/core/descriptor-meta.ts (1)

37-64: Consider reusing the lowering constants to avoid duplication.

The cosineDistanceLowering and cosineSimilarityLowering constants are defined at lines 6-16, but the same template strings are duplicated inline in pgvectorQueryOperations. Reusing the constants improves maintainability and ensures consistency.

♻️ Suggested refactor to reuse lowering constants
 export const pgvectorQueryOperations: readonly QueryOperationDescriptor[] = [
   {
     method: 'cosineDistance',
     args: [
       { codecId: pgvectorTypeId, nullable: false },
       { codecId: pgvectorTypeId, nullable: false },
     ],
     returns: { codecId: 'pg/float8@1', nullable: false },
-    lowering: {
-      targetFamily: 'sql',
-      strategy: 'function',
-      template: '{{self}} <=> {{arg0}}',
-    },
+    lowering: cosineDistanceLowering,
   },
   {
     method: 'cosineSimilarity',
     args: [
       { codecId: pgvectorTypeId, nullable: false },
       { codecId: pgvectorTypeId, nullable: false },
     ],
     returns: { codecId: 'pg/float8@1', nullable: false },
-    lowering: {
-      targetFamily: 'sql',
-      strategy: 'function',
-      template: '1 - ({{self}} <=> {{arg0}})',
-    },
+    lowering: cosineSimilarityLowering,
   },
 ];
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/3-extensions/pgvector/src/core/descriptor-meta.ts` around lines 37 -
64, The pgvectorQueryOperations array duplicates the lowering objects inline for
cosineDistance and cosineSimilarity; replace those inline lowering objects by
referencing the existing constants cosineDistanceLowering and
cosineSimilarityLowering instead (update the entries in pgvectorQueryOperations
so each operation's lowering property is assigned the corresponding constant),
ensuring the types remain QueryOperationDescriptor and no other fields change.
packages/3-extensions/pgvector/test/operations.test.ts (1)

29-49: Prefer toMatchObject for multiple related assertions on the same object.

The coding guidelines recommend using object matchers over multiple individual expect().toBe() or expect().toEqual() calls when checking 2 or more related values. Both operation blocks could be consolidated.

♻️ Suggested refactor using toMatchObject
     const cosineDistanceOp = operations.find((op) => op.method === 'cosineDistance');
-    expect(cosineDistanceOp).toBeDefined();
-    expect(cosineDistanceOp?.forTypeId).toBe('pg/vector@1');
-    expect(cosineDistanceOp?.args).toEqual([{ kind: 'param' }]);
-    expect(cosineDistanceOp?.returns).toEqual({ kind: 'builtin', type: 'number' });
-    expect(cosineDistanceOp?.lowering).toEqual({
-      targetFamily: 'sql',
-      strategy: 'function',
-      template: '{{self}} <=> {{arg0}}',
-    });
+    expect(cosineDistanceOp).toMatchObject({
+      method: 'cosineDistance',
+      forTypeId: 'pg/vector@1',
+      args: [{ kind: 'param' }],
+      returns: { kind: 'builtin', type: 'number' },
+      lowering: {
+        targetFamily: 'sql',
+        strategy: 'function',
+        template: '{{self}} <=> {{arg0}}',
+      },
+    });

     const cosineSimilarityOp = operations.find((op) => op.method === 'cosineSimilarity');
-    expect(cosineSimilarityOp).toBeDefined();
-    expect(cosineSimilarityOp?.forTypeId).toBe('pg/vector@1');
-    expect(cosineSimilarityOp?.args).toEqual([{ kind: 'param' }]);
-    expect(cosineSimilarityOp?.returns).toEqual({ kind: 'builtin', type: 'number' });
-    expect(cosineSimilarityOp?.lowering).toEqual({
-      targetFamily: 'sql',
-      strategy: 'function',
-      template: '1 - ({{self}} <=> {{arg0}})',
-    });
+    expect(cosineSimilarityOp).toMatchObject({
+      method: 'cosineSimilarity',
+      forTypeId: 'pg/vector@1',
+      args: [{ kind: 'param' }],
+      returns: { kind: 'builtin', type: 'number' },
+      lowering: {
+        targetFamily: 'sql',
+        strategy: 'function',
+        template: '1 - ({{self}} <=> {{arg0}})',
+      },
+    });

As per coding guidelines: "Prefer object matchers (toMatchObject) over multiple individual expect().toBe() calls when checking 2 or more related values in tests"

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/3-extensions/pgvector/test/operations.test.ts` around lines 29 - 49,
Consolidate the multiple assertions for each operation into a single object
matcher: replace the repeated expects on cosineDistanceOp and cosineSimilarityOp
(found via operations.find) with expect(cosineDistanceOp).toMatchObject({...})
and expect(cosineSimilarityOp).toMatchObject({...}) respectively, including
forTypeId, args, returns and lowering (with lowering.template,
lowering.strategy, lowering.targetFamily) so each block verifies the related
fields in one matcher instead of multiple toBe/toEqual calls.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts`:
- Around line 42-53: The test "cosineSimilarity filters in WHERE" only asserts
presence of the matching row (id === 1) and should also assert exclusion of an
orthogonal row to catch regressions; update the test that calls
db().posts.select('id').where((f, fns) =>
fns.gt(fns.cosineSimilarity(f.embedding, [1, 0, 0]), 0.5)).all() to include an
explicit negative assertion such as expect(rows.some(r => r.id ===
3)).toBe(false) (or equivalent) so the orthogonal embedding is confirmed
filtered out.

In `@packages/3-extensions/pgvector/src/core/descriptor-meta.ts`:
- Around line 37-64: The pgvectorQueryOperations array duplicates the lowering
objects inline for cosineDistance and cosineSimilarity; replace those inline
lowering objects by referencing the existing constants cosineDistanceLowering
and cosineSimilarityLowering instead (update the entries in
pgvectorQueryOperations so each operation's lowering property is assigned the
corresponding constant), ensuring the types remain QueryOperationDescriptor and
no other fields change.

In `@packages/3-extensions/pgvector/test/operations.test.ts`:
- Around line 29-49: Consolidate the multiple assertions for each operation into
a single object matcher: replace the repeated expects on cosineDistanceOp and
cosineSimilarityOp (found via operations.find) with
expect(cosineDistanceOp).toMatchObject({...}) and
expect(cosineSimilarityOp).toMatchObject({...}) respectively, including
forTypeId, args, returns and lowering (with lowering.template,
lowering.strategy, lowering.targetFamily) so each block verifies the related
fields in one matcher instead of multiple toBe/toEqual calls.

In `@packages/3-extensions/pgvector/test/result-type.types.test-d.ts`:
- Around line 321-325: The test currently infers Row via ResultType<typeof
_plan> and checks assignment to number indirectly; add an explicit expectTypeOf
assertion for Row['similarity'] to lock its static type to number. Locate the
Row/ResultType/_plan usage in the test and add an expectTypeOf assertion that
compares Row['similarity'] to number (e.g.,
expectTypeOf<Row['similarity']>().toEqualTypeOf<number>()) so the type cannot
widen to any/unknown.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 3443e60d-92b4-4dff-886c-5c6aad5e6093

📥 Commits

Reviewing files that changed from the base of the PR and between 95f2de4 and e365e2b.

📒 Files selected for processing (11)
  • packages/2-sql/4-lanes/sql-builder-new/test/integration/extension-functions.test.ts
  • packages/3-extensions/pgvector/README.md
  • packages/3-extensions/pgvector/src/core/descriptor-meta.ts
  • packages/3-extensions/pgvector/src/exports/control.ts
  • packages/3-extensions/pgvector/src/exports/runtime.ts
  • packages/3-extensions/pgvector/src/types/operation-types.ts
  • packages/3-extensions/pgvector/test/manifest.test.ts
  • packages/3-extensions/pgvector/test/operations.test.ts
  • packages/3-extensions/pgvector/test/result-type.types.test-d.ts
  • test/integration/test/pgvector.test.ts
  • test/utils/src/operation-descriptors.ts

@aqrln aqrln force-pushed the aqrln-qvsylnyzyxrs branch from e365e2b to 6ad46fb Compare March 31, 2026 14:54
@aqrln aqrln force-pushed the aqrln-runovwrkulrp branch from 95f2de4 to a283845 Compare March 31, 2026 14:54
Base automatically changed from aqrln-runovwrkulrp to main March 31, 2026 15:00
Follow up to <#270>.

Add a separate `cosineSimilarity` operation with `1 - ({{self}} <=>
{{arg0}})` lowering because it is also useful.
@aqrln aqrln force-pushed the aqrln-qvsylnyzyxrs branch from 6ad46fb to 7fc9d6f Compare March 31, 2026 15:03
@aqrln aqrln enabled auto-merge (squash) March 31, 2026 15:08
@aqrln aqrln merged commit 608e909 into main Mar 31, 2026
15 checks passed
@aqrln aqrln deleted the aqrln-qvsylnyzyxrs branch March 31, 2026 15:10
wmadden pushed a commit that referenced this pull request Apr 1, 2026
Follow up to <#270>.

Add a separate `cosineSimilarity` operation with `1 - ({{self}} <=>
{{arg0}})` lowering because it is also useful.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added `cosineSimilarity` operation for pgvector extension, enabling
vector similarity calculations computed as 1 minus cosine distance, with
results ranging from 0 to 1.

* **Documentation**
* Updated pgvector README with `cosineSimilarity` operation
documentation, including TypeScript signatures and SQL rendering
examples.

* **Tests**
* Added integration tests validating `cosineSimilarity` operation
behavior and query results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
jkomyno pushed a commit that referenced this pull request Apr 1, 2026
Follow up to <#270>.

Add a separate `cosineSimilarity` operation with `1 - ({{self}} <=>
{{arg0}})` lowering because it is also useful.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Release Notes

* **New Features**
* Added `cosineSimilarity` operation for pgvector extension, enabling
vector similarity calculations computed as 1 minus cosine distance, with
results ranging from 0 to 1.

* **Documentation**
* Updated pgvector README with `cosineSimilarity` operation
documentation, including TypeScript signatures and SQL rendering
examples.

* **Tests**
* Added integration tests validating `cosineSimilarity` operation
behavior and query results.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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

Successfully merging this pull request may close these issues.

3 participants