vector.d.cts 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import type { AnyColumn } from "../../column.cjs";
  2. import type { TypedQueryBuilder } from "../../query-builders/query-builder.cjs";
  3. import { type SQL, type SQLWrapper } from "../sql.cjs";
  4. /**
  5. * Used in sorting and in querying, if used in sorting,
  6. * this specifies that the given column or expression should be sorted in an order
  7. * that minimizes the L2 distance to the given value.
  8. * If used in querying, this specifies that it should return the L2 distance
  9. * between the given column or expression and the given value.
  10. *
  11. * ## Examples
  12. *
  13. * ```ts
  14. * // Sort cars by embedding similarity
  15. * // to the given embedding
  16. * db.select().from(cars)
  17. * .orderBy(l2Distance(cars.embedding, embedding));
  18. * ```
  19. *
  20. * ```ts
  21. * // Select distance of cars and embedding
  22. * // to the given embedding
  23. * db.select({distance: l2Distance(cars.embedding, embedding)}).from(cars)
  24. * ```
  25. */
  26. export declare function l2Distance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
  27. /**
  28. * L1 distance is one of the possible distance measures between two probability distribution vectors and it is
  29. * calculated as the sum of the absolute differences.
  30. * The smaller the distance between the observed probability vectors, the higher the accuracy of the synthetic data
  31. *
  32. * ## Examples
  33. *
  34. * ```ts
  35. * // Sort cars by embedding similarity
  36. * // to the given embedding
  37. * db.select().from(cars)
  38. * .orderBy(l1Distance(cars.embedding, embedding));
  39. * ```
  40. *
  41. * ```ts
  42. * // Select distance of cars and embedding
  43. * // to the given embedding
  44. * db.select({distance: l1Distance(cars.embedding, embedding)}).from(cars)
  45. * ```
  46. */
  47. export declare function l1Distance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
  48. /**
  49. * Used in sorting and in querying, if used in sorting,
  50. * this specifies that the given column or expression should be sorted in an order
  51. * that minimizes the inner product distance to the given value.
  52. * If used in querying, this specifies that it should return the inner product distance
  53. * between the given column or expression and the given value.
  54. *
  55. * ## Examples
  56. *
  57. * ```ts
  58. * // Sort cars by embedding similarity
  59. * // to the given embedding
  60. * db.select().from(cars)
  61. * .orderBy(innerProduct(cars.embedding, embedding));
  62. * ```
  63. *
  64. * ```ts
  65. * // Select distance of cars and embedding
  66. * // to the given embedding
  67. * db.select({ distance: innerProduct(cars.embedding, embedding) }).from(cars)
  68. * ```
  69. */
  70. export declare function innerProduct(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
  71. /**
  72. * Used in sorting and in querying, if used in sorting,
  73. * this specifies that the given column or expression should be sorted in an order
  74. * that minimizes the cosine distance to the given value.
  75. * If used in querying, this specifies that it should return the cosine distance
  76. * between the given column or expression and the given value.
  77. *
  78. * ## Examples
  79. *
  80. * ```ts
  81. * // Sort cars by embedding similarity
  82. * // to the given embedding
  83. * db.select().from(cars)
  84. * .orderBy(cosineDistance(cars.embedding, embedding));
  85. * ```
  86. *
  87. * ```ts
  88. * // Select distance of cars and embedding
  89. * // to the given embedding
  90. * db.select({distance: cosineDistance(cars.embedding, embedding)}).from(cars)
  91. * ```
  92. */
  93. export declare function cosineDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
  94. /**
  95. * Hamming distance between two strings or vectors of equal length is the number of positions at which the
  96. * corresponding symbols are different. In other words, it measures the minimum number of
  97. * substitutions required to change one string into the other, or equivalently,
  98. * the minimum number of errors that could have transformed one string into the other
  99. *
  100. * ## Examples
  101. *
  102. * ```ts
  103. * // Sort cars by embedding similarity
  104. * // to the given embedding
  105. * db.select().from(cars)
  106. * .orderBy(hammingDistance(cars.embedding, embedding));
  107. * ```
  108. */
  109. export declare function hammingDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;
  110. /**
  111. * ## Examples
  112. *
  113. * ```ts
  114. * // Sort cars by embedding similarity
  115. * // to the given embedding
  116. * db.select().from(cars)
  117. * .orderBy(jaccardDistance(cars.embedding, embedding));
  118. * ```
  119. */
  120. export declare function jaccardDistance(column: SQLWrapper | AnyColumn, value: number[] | string[] | TypedQueryBuilder<any> | string): SQL;