Skip to content

Commit

Permalink
[VEC-32] Add a few more VectorDistanceMetric (#1)
Browse files Browse the repository at this point in the history
* Added index_similarity_metric option to client
* Added Jenkinsfile
* Running Jenkinsfile command in bash
* Updated version

---------

Co-authored-by: Jesse Schmidt <jschmidt@aerospike.com>
  • Loading branch information
abhilashmandaliya and Jesse Schmidt authored Dec 20, 2023
1 parent 0b165de commit 76cc0f3
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 25 deletions.
52 changes: 52 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pipeline {
agent any

options {
disableConcurrentBuilds()
buildDiscarder(logRotator(numToKeepStr: '5', artifactNumToKeepStr: '5'))
}

stages {
stage("Pipeline") {
stages {
stage("Checkout") {
steps {
checkout([
$class : 'GitSCM',
branches : scm.branches,
extensions : scm.extensions + [[$class: 'CleanBeforeCheckout']],
userRemoteConfigs: scm.userRemoteConfigs
])
}
}

stage("Build") {
steps {
echo "Building.."
sh "python3 -m venv .venv"
sh '''#!/bin/bash
source .venv/bin/activate
'''
sh "./proto/codegen.sh"
sh "python3 -m pip install build"
sh "python3 -m build"
}
}

stage("Upload") {
steps {
echo "Uploading archives.."
sh "python3 -m pip install twine"
sh "python3 -m twine upload --repository ecosystem-python-dev-local dist/*"
}
}
}
}
}

post {
cleanup {
cleanWs()
}
}
}
27 changes: 18 additions & 9 deletions proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ message Key {
}
}

message BoolArray {
message BoolData {
repeated bool value = 1;
}

message FloatArray {
message FloatData {
repeated float value = 1;
}

Expand Down Expand Up @@ -70,9 +70,8 @@ message List {
message Vector {
// Vector data
oneof data {
// TODO: rename to bool data and float data.
BoolArray boolArray = 1;
FloatArray floatArray = 2;
BoolData boolData = 1;
FloatData floatData = 2;
}
}

Expand Down Expand Up @@ -136,6 +135,14 @@ message IndexId {
string namespace = 2;
}

enum VectorDistanceMetric {
SQUARED_EUCLIDEAN = 0;
COSINE = 1;
DOT_PRODUCT = 2;
MANHATTAN = 3;
HAMMING = 4;
}

enum IndexType {
HNSW = 0;
}
Expand All @@ -147,17 +154,19 @@ message IndexDefinition {

IndexType type = 2;

VectorDistanceMetric vectorDistanceMetric = 3;

// Optional Aerospike set name.
optional string set = 3;
optional string set = 4;

// Indexed vector bin.
string bin = 4;
string bin = 5;

// Number of dimensions in data.
// Vectors not matching the dimension count will not be indexed.
uint32 dimensions = 5;
uint32 dimensions = 6;

map<string, Value> params = 6;
map<string, Value> params = 7;
}

// List of index definitions.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Database"
]
version = "0.2.0"
version = "0.3.0.dev1"
requires-python = ">3.8"
dependencies = [
"grpcio",
Expand Down
8 changes: 4 additions & 4 deletions src/aerospike_vector/conversions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def fromVectorDbValue(input: types_pb2.Value) -> Any:
return [fromVectorDbValue(v) for v in input.listValue.entries]
elif input.HasField("vectorValue"):
vector = input.vectorValue
if vector.HasField("floatArray"):
return [v for v in vector.floatArray.value]
if vector.HasField("boolArray"):
return [v for v in vector.boolArray.value]
if vector.HasField("floatData"):
return [v for v in vector.floatData.value]
if vector.HasField("boolData"):
return [v for v in vector.boolData.value]

return None
22 changes: 12 additions & 10 deletions src/aerospike_vector/types_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/aerospike_vector/vectordb_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def __init__(self, seeds: types.HostPort | tuple[types.HostPort, ...],

def indexCreate(self, namespace: str, name: str, set: str,
vector_bin_name: str, dimensions: int,
params: dict[str, Any] = None):
params: dict[str, Any] = None,
index_similarity_metric: types_pb2.VectorDistanceMetric =
types_pb2.VectorDistanceMetric.SQUARED_EUCLIDEAN):
"""Create an index"""
index_stub = index_pb2_grpc.IndexServiceStub(
self.channelProvider.getChannel())
Expand All @@ -47,6 +49,7 @@ def indexCreate(self, namespace: str, name: str, set: str,
types_pb2.IndexDefinition(
id=types_pb2.IndexId(namespace=namespace, name=name),
set=set,
vectorDistanceMetric=index_similarity_metric,
bin=vector_bin_name,
dimensions=dimensions,
params=grpcParams))
Expand Down

0 comments on commit 76cc0f3

Please sign in to comment.