recommend
postgresql_extension · Experimental C extension providing scalar distance, text similarity, and one-dimensional array similarity functions derived from smlar.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100399 | recommend | postgresql_extension | 1.0 | FUNC | Unknown | C |
Usage
Sources:
recommend is an experimental PostgreSQL 9.5-era extension with numeric distance, text character-vector similarity, and one-dimensional array similarity functions derived from smlar. It is not a complete recommendation system: callers must build candidate selection, ranking, persistence, and evaluation around these low-level scores.
Core Workflow
After installing a build that has been reviewed and repaired as described below, the intended API is:
twoint and two_float return absolute difference. arraysml compares arrays of the same element type; its default bundled formula is cosine-style set similarity.
API
twoint(integer, integer) RETURNS integer: integer absolute difference.two_float(double precision, double precision) RETURNS double precision: floating-point absolute difference.similarity(text, text) RETURNS real: cosine similarity of a custom character-count vector.arraysml(anyarray, anyarray) RETURNS real: similarity for comparable one-dimensional arrays, with bundledsmlarformula/configuration code.
Caveats
The pinned official C source is not reproducibly buildable as published: generate_vect is missing its opening function brace. Its similarity implementation also computes an array index as each input byte minus lowercase a without bounds checks, so uppercase, punctuation, multibyte text, and other bytes can access memory outside the vector. Do not expose that function or claim a verified build without reviewing and patching the source.
The code targets old PostgreSQL internal APIs and has no maintained compatibility statement beyond the README’s PostgreSQL 9.5 claim. twoint can overflow for extreme integers, empty text can divide by zero in cosine calculation, and array scoring depends on element comparison/canonicalization. Treat every result as an experimental score and validate a patched build with adversarial input before use.