tanimoto
tanimoto · Fast C implementation of the Tanimoto similarity coefficient for PostgreSQL bit-varying fingerprints.
Overview
Usage
Sources:
tanimoto 1.0 computes the Tanimoto/Jaccard similarity of two binary fingerprints: set bits in the intersection divided by set bits in the union. Its optimized tanimoto_c(bit varying, bit varying) function is intended for equal-length, byte-aligned chemical or feature fingerprints.
Setup and Basic Query
The installation SQL also creates cdk.tanimoto(...) but does not declare or create the cdk schema. Ensure that schema exists before creating the extension.
The result is a real value between 0 and 1 when the union contains at least one set bit: 1 means identical sets of enabled bits and 0 means no shared enabled bits.
Functions and Preconditions
tanimoto_c(bit varying, bit varying)uses a C byte-popcount lookup table. It raises an error if lengths differ or if the bit length is not divisible by 8.cdk.tanimoto(bit varying, bit varying)is a SQL implementation using bitwise&and|plus textual bit counting. It is slower and tied to the fixedcdkschema.- Both functions are strict, immutable, parallel safe, leakproof, and security invoker in the extension SQL.
The similarity of two all-zero fingerprints has a zero denominator and is mathematically undefined; exclude that case or choose an explicit application convention. Do not silently compare fingerprints generated by different algorithms, lengths, bit ordering, or feature dictionaries.
Packaging and Compatibility
Although the control file says relocatable = true, the hard-coded cdk.tanimoto object makes the extension effectively dependent on the cdk schema. The SQL also uses modern function attributes such as PARALLEL SAFE and LEAKPROOF, and the latter requires privileged installation. The repository provides no README, release notes, or supported PostgreSQL matrix; compile and run representative bit-pattern tests on the exact server before use.