vector.cjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var vector_exports = {};
  20. __export(vector_exports, {
  21. cosineDistance: () => cosineDistance,
  22. hammingDistance: () => hammingDistance,
  23. innerProduct: () => innerProduct,
  24. jaccardDistance: () => jaccardDistance,
  25. l1Distance: () => l1Distance,
  26. l2Distance: () => l2Distance
  27. });
  28. module.exports = __toCommonJS(vector_exports);
  29. var import_sql = require("../sql.cjs");
  30. function toSql(value) {
  31. return JSON.stringify(value);
  32. }
  33. function l2Distance(column, value) {
  34. if (Array.isArray(value)) {
  35. return import_sql.sql`${column} <-> ${toSql(value)}`;
  36. }
  37. return import_sql.sql`${column} <-> ${value}`;
  38. }
  39. function l1Distance(column, value) {
  40. if (Array.isArray(value)) {
  41. return import_sql.sql`${column} <+> ${toSql(value)}`;
  42. }
  43. return import_sql.sql`${column} <+> ${value}`;
  44. }
  45. function innerProduct(column, value) {
  46. if (Array.isArray(value)) {
  47. return import_sql.sql`${column} <#> ${toSql(value)}`;
  48. }
  49. return import_sql.sql`${column} <#> ${value}`;
  50. }
  51. function cosineDistance(column, value) {
  52. if (Array.isArray(value)) {
  53. return import_sql.sql`${column} <=> ${toSql(value)}`;
  54. }
  55. return import_sql.sql`${column} <=> ${value}`;
  56. }
  57. function hammingDistance(column, value) {
  58. if (Array.isArray(value)) {
  59. return import_sql.sql`${column} <~> ${toSql(value)}`;
  60. }
  61. return import_sql.sql`${column} <~> ${value}`;
  62. }
  63. function jaccardDistance(column, value) {
  64. if (Array.isArray(value)) {
  65. return import_sql.sql`${column} <%> ${toSql(value)}`;
  66. }
  67. return import_sql.sql`${column} <%> ${value}`;
  68. }
  69. // Annotate the CommonJS export names for ESM import in node:
  70. 0 && (module.exports = {
  71. cosineDistance,
  72. hammingDistance,
  73. innerProduct,
  74. jaccardDistance,
  75. l1Distance,
  76. l2Distance
  77. });
  78. //# sourceMappingURL=vector.cjs.map