mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-22 03:57:34 +08:00
Compare commits
5 Commits
v0.8.2
...
sparsevec-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
434ef7a5ab | ||
|
|
17916cad00 | ||
|
|
284f2f0fec | ||
|
|
edd49863ba | ||
|
|
411291189d |
@@ -1,6 +1,6 @@
|
||||
## 0.8.2 (2026-02-25)
|
||||
|
||||
- Fixed buffer overflow with parallel HNSW index build
|
||||
- Fixed buffer overflow with parallel HNSW index build - [more info](https://github.com/pgvector/pgvector/issues/959)
|
||||
- Improved `install` target on Windows
|
||||
- Fixed `Index Searches` in `EXPLAIN` output for Postgres 18
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/parallel.h"
|
||||
#include "access/relscan.h"
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "access/genam.h"
|
||||
#include "access/relscan.h"
|
||||
#include "hnsw.h"
|
||||
@@ -151,7 +153,7 @@ hnswbeginscan(Relation index, int nkeys, int norderbys)
|
||||
/* Calculate max memory */
|
||||
/* Add 256 extra bytes to fill last block when close */
|
||||
maxMemory = (double) work_mem * hnsw_scan_mem_multiplier * 1024.0 + 256;
|
||||
so->maxMemory = Min(maxMemory, (double) SIZE_MAX);
|
||||
so->maxMemory = Min(maxMemory, (double) (SIZE_MAX / 2));
|
||||
|
||||
scan->opaque = so;
|
||||
|
||||
|
||||
@@ -895,28 +895,24 @@ SparsevecInnerProduct(SparseVector * a, SparseVector * b)
|
||||
float *ax = SPARSEVEC_VALUES(a);
|
||||
float *bx = SPARSEVEC_VALUES(b);
|
||||
float distance = 0.0;
|
||||
int bpos = 0;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
|
||||
for (int i = 0; i < a->nnz; i++)
|
||||
while (i < a->nnz && j < b->nnz)
|
||||
{
|
||||
int ai = a->indices[i];
|
||||
int bi = b->indices[j];
|
||||
|
||||
for (int j = bpos; j < b->nnz; j++)
|
||||
if (ai == bi)
|
||||
{
|
||||
int bi = b->indices[j];
|
||||
|
||||
/* Only update when the same index */
|
||||
if (ai == bi)
|
||||
distance += ax[i] * bx[j];
|
||||
|
||||
/* Update start for next iteration */
|
||||
if (ai >= bi)
|
||||
bpos = j + 1;
|
||||
|
||||
/* Found or passed it */
|
||||
if (bi >= ai)
|
||||
break;
|
||||
distance += ax[i] * bx[j];
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
else if (ai < bi)
|
||||
i++;
|
||||
else
|
||||
j++;
|
||||
}
|
||||
|
||||
return distance;
|
||||
|
||||
Reference in New Issue
Block a user