Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PgVectorStoreProperties {

private PgIndexType indexType = PgIndexType.HNSW;

private PgDistanceType distanceType = PgDistanceType.CosineDistance;
private PgDistanceType distanceType = PgDistanceType.COSINE_DISTANCE;

private boolean removeExistingVectorStoreTable = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PgVectorStorePropertiesTests {
public void defaultValues() {
var props = new PgVectorStoreProperties();
assertThat(props.getDimensions()).isEqualTo(PgVectorStore.INVALID_EMBEDDING_DIMENSION);
assertThat(props.getDistanceType()).isEqualTo(PgDistanceType.CosineDistance);
assertThat(props.getDistanceType()).isEqualTo(PgDistanceType.COSINE_DISTANCE);
assertThat(props.getIndexType()).isEqualTo(PgIndexType.HNSW);
assertThat(props.isRemoveExistingVectorStoreTable()).isFalse();
}
Expand All @@ -43,12 +43,12 @@ public void customValues() {
var props = new PgVectorStoreProperties();

props.setDimensions(1536);
props.setDistanceType(PgDistanceType.EuclideanDistance);
props.setDistanceType(PgDistanceType.EUCLIDEAN_DISTANCE);
props.setIndexType(PgIndexType.IVFFLAT);
props.setRemoveExistingVectorStoreTable(true);

assertThat(props.getDimensions()).isEqualTo(1536);
assertThat(props.getDistanceType()).isEqualTo(PgDistanceType.EuclideanDistance);
assertThat(props.getDistanceType()).isEqualTo(PgDistanceType.EUCLIDEAN_DISTANCE);
assertThat(props.getIndexType()).isEqualTo(PgIndexType.IVFFLAT);
assertThat(props.isRemoveExistingVectorStoreTable()).isTrue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,17 @@ public enum PgDistanceType {
// embeddings), use inner product for best performance.
// The Sentence transformers are NOT normalized:
// https://github.com/UKPLab/sentence-transformers/issues/233
EuclideanDistance("<->", "vector_l2_ops",
EUCLIDEAN_DISTANCE("<->", "vector_l2_ops",
"SELECT *, embedding <-> ? AS distance FROM %s WHERE embedding <-> ? < ? %s ORDER BY distance LIMIT ? "),

// NOTE: works only if If vectors are normalized to length 1 (like OpenAI
// embeddings), use inner product for best performance.
// The Sentence transformers are NOT normalized:
// https://github.com/UKPLab/sentence-transformers/issues/233
NegativeInnerProduct("<#>", "vector_ip_ops",
NEGATIVE_INNER_PRODUCT("<#>", "vector_ip_ops",
"SELECT *, (1 + (embedding <#> ?)) AS distance FROM %s WHERE (1 + (embedding <#> ?)) < ? %s ORDER BY distance LIMIT ? "),

CosineDistance("<=>", "vector_cosine_ops",
COSINE_DISTANCE("<=>", "vector_cosine_ops",
"SELECT *, embedding <=> ? AS distance FROM %s WHERE embedding <=> ? < ? %s ORDER BY distance LIMIT ? ");

public final String operator;
Expand Down Expand Up @@ -197,12 +197,12 @@ private Map<String, Object> toMap(PGobject pgObject) {
}

public PgVectorStore(JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient) {
this(jdbcTemplate, embeddingClient, INVALID_EMBEDDING_DIMENSION, PgVectorStore.PgDistanceType.CosineDistance,
this(jdbcTemplate, embeddingClient, INVALID_EMBEDDING_DIMENSION, PgVectorStore.PgDistanceType.COSINE_DISTANCE,
false, PgIndexType.NONE);
}

public PgVectorStore(JdbcTemplate jdbcTemplate, EmbeddingClient embeddingClient, int dimensions) {
this(jdbcTemplate, embeddingClient, dimensions, PgVectorStore.PgDistanceType.CosineDistance, false,
this(jdbcTemplate, embeddingClient, dimensions, PgVectorStore.PgDistanceType.COSINE_DISTANCE, false,
PgIndexType.NONE);
}

Expand Down