Skip to content

Commit

Permalink
Return id(s) when calling Index::addItem and Index::addItems in Java …
Browse files Browse the repository at this point in the history
…bindings (#94)

* Return id(s) when calling Index::addItem and Index::addItems in Java bindings

* Update Java docs

* Update tests

* Update java/com_spotify_voyager_jni_Index.cpp

Co-authored-by: Peter Sobot <[email protected]>

* Update java/com_spotify_voyager_jni_Index.cpp

Co-authored-by: Peter Sobot <[email protected]>

* Format C++

* Return a non-void value to ensure every possible control path has a return statement

---------

Co-authored-by: Peter Sobot <[email protected]>
  • Loading branch information
stephen29xie and psobot authored Dec 13, 2024
1 parent fefed3d commit d68175e
Show file tree
Hide file tree
Showing 42 changed files with 162 additions and 119 deletions.
4 changes: 2 additions & 2 deletions docs/java/apidocs/allclasses-index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>All Classes and Interfaces (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="class index">
<meta name="generator" content="javadoc/AllClassesIndexWriter">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
Expand Down
4 changes: 2 additions & 2 deletions docs/java/apidocs/allpackages-index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>All Packages (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="package index">
<meta name="generator" content="javadoc/AllPackagesIndexWriter">
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Index.QueryResults (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="declaration: package: com.spotify.voyager.jni, class: Index, class: QueryResults">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Index.SpaceType (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="declaration: package: com.spotify.voyager.jni, class: Index, enum: SpaceType">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Index.StorageDataType (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="declaration: package: com.spotify.voyager.jni, class: Index, enum: StorageDataType">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
Expand Down
34 changes: 22 additions & 12 deletions docs/java/apidocs/com/spotify/voyager/jni/Index.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Index (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="declaration: package: com.spotify.voyager.jni, class: Index">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
Expand Down Expand Up @@ -175,29 +175,29 @@ <h2>Method Summary</h2>
<div class="table-header col-first">Modifier and Type</div>
<div class="table-header col-second">Method</div>
<div class="table-header col-last">Description</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>long</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#addItem(float%5B%5D)" class="member-name-link">addItem</a><wbr>(float[]&nbsp;vector)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Add an item (a vector) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a>.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>long</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#addItem(float%5B%5D,long)" class="member-name-link">addItem</a><wbr>(float[]&nbsp;vector,
long&nbsp;id)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Add an item (a vector) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a> with the provided identifier.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>long[]</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#addItems(float%5B%5D%5B%5D,int)" class="member-name-link">addItems</a><wbr>(float[][]&nbsp;vectors,
int&nbsp;numThreads)</code></div>
<div class="col-last even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Add multiple items (vectors) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a>.</div>
</div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>void</code></div>
<div class="col-first odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>long[]</code></div>
<div class="col-second odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#addItems(float%5B%5D%5B%5D,long%5B%5D,int)" class="member-name-link">addItems</a><wbr>(float[][]&nbsp;vectors,
long[]&nbsp;ids,
int&nbsp;numThreads)</code></div>
<div class="col-last odd-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4">
<div class="block">Add multiple items (vectors) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a>.</div>
<div class="block">Add multiple items (vectors) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a> with the provided identifiers.</div>
</div>
<div class="col-first even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code>byte[]</code></div>
<div class="col-second even-row-color method-summary-table method-summary-table-tab2 method-summary-table-tab4"><code><a href="#asBytes()" class="member-name-link">asBytes</a>()</code></div>
Expand Down Expand Up @@ -669,12 +669,14 @@ <h3>asBytes</h3>
<li>
<section class="detail" id="addItem(float[])">
<h3>addItem</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">addItem</span><wbr><span class="parameters">(float[]&nbsp;vector)</span></div>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">long</span>&nbsp;<span class="element-name">addItem</span><wbr><span class="parameters">(float[]&nbsp;vector)</span></div>
<div class="block">Add an item (a vector) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a>. The item will automatically be given an
identifier equal to the return value of <a href="#getNumElements()"><code>getNumElements()</code></a>.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>vector</code> - The vector to add to the index.</dd>
<dt>Returns:</dt>
<dd>The <code>long</code> ID that was assigned to this vector.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html" title="class or interface in java.lang" class="external-link">RuntimeException</a></code> - If the provided vector does not contain exactly <a href="#getNumDimensions()"><code>getNumDimensions()</code></a> dimensions.</dd>
</dl>
Expand All @@ -683,13 +685,15 @@ <h3>addItem</h3>
<li>
<section class="detail" id="addItem(float[],long)">
<h3>addItem</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">addItem</span><wbr><span class="parameters">(float[]&nbsp;vector,
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">long</span>&nbsp;<span class="element-name">addItem</span><wbr><span class="parameters">(float[]&nbsp;vector,
long&nbsp;id)</span></div>
<div class="block">Add an item (a vector) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a> with the provided identifier.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>vector</code> - The vector to add to the index.</dd>
<dd><code>id</code> - The 64-bit integer denoting the identifier of this vector.</dd>
<dt>Returns:</dt>
<dd>The <code>long</code> ID that was assigned to this vector.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html" title="class or interface in java.lang" class="external-link">RuntimeException</a></code> - If the provided vector does not contain exactly <a href="#getNumDimensions()"><code>getNumDimensions()</code></a> dimensions.</dd>
</dl>
Expand All @@ -698,14 +702,17 @@ <h3>addItem</h3>
<li>
<section class="detail" id="addItems(float[][],int)">
<h3>addItems</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">addItems</span><wbr><span class="parameters">(float[][]&nbsp;vectors,
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">long[]</span>&nbsp;<span class="element-name">addItems</span><wbr><span class="parameters">(float[][]&nbsp;vectors,
int&nbsp;numThreads)</span></div>
<div class="block">Add multiple items (vectors) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a>.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>vectors</code> - The vectors to add to the index.</dd>
<dd><code>numThreads</code> - The number of threads to use when adding the provided vectors. If -1 (the
default), the number of CPUs available on the current machine will be used.</dd>
<dt>Returns:</dt>
<dd>The auto-generated <code>long</code> IDs that were assigned to the provided vectors, in the
same order as the provided vectors.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html" title="class or interface in java.lang" class="external-link">RuntimeException</a></code> - If any of the provided vectors do not contain exactly <a href="#getNumDimensions()"><code>getNumDimensions()</code></a> dimensions.</dd>
</dl>
Expand All @@ -714,10 +721,10 @@ <h3>addItems</h3>
<li>
<section class="detail" id="addItems(float[][],long[],int)">
<h3>addItems</h3>
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">void</span>&nbsp;<span class="element-name">addItems</span><wbr><span class="parameters">(float[][]&nbsp;vectors,
<div class="member-signature"><span class="modifiers">public</span>&nbsp;<span class="return-type">long[]</span>&nbsp;<span class="element-name">addItems</span><wbr><span class="parameters">(float[][]&nbsp;vectors,
long[]&nbsp;ids,
int&nbsp;numThreads)</span></div>
<div class="block">Add multiple items (vectors) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a>.</div>
<div class="block">Add multiple items (vectors) to this <a href="Index.html" title="class in com.spotify.voyager.jni"><code>Index</code></a> with the provided identifiers.</div>
<dl class="notes">
<dt>Parameters:</dt>
<dd><code>vectors</code> - The vectors to add to the index.</dd>
Expand All @@ -727,6 +734,9 @@ <h3>addItems</h3>
causes a temporary C++ thread pool to be used. Instead of calling <a href="#addItems(float%5B%5D%5B%5D,int)"><code>addItems(float[][],int)</code></a> in a
tight loop, consider passing more data to each <a href="#addItems(float%5B%5D%5B%5D,int)"><code>addItems(float[][],int)</code></a> call instead to reduce
overhead.</dd>
<dt>Returns:</dt>
<dd>The <code>long</code> IDs that were assigned to the provided vectors, in the same order as
the provided vectors.</dd>
<dt>Throws:</dt>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html" title="class or interface in java.lang" class="external-link">RuntimeException</a></code> - If any of the provided vectors do not contain exactly <a href="#getNumDimensions()"><code>getNumDimensions()</code></a> dimensions.</dd>
<dd><code><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html" title="class or interface in java.lang" class="external-link">RuntimeException</a></code> - If the list of IDs does not have the same length as the list of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>StringIndex.QueryResults (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="declaration: package: com.spotify.voyager.jni, class: StringIndex, class: QueryResults">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
Expand Down
4 changes: 2 additions & 2 deletions docs/java/apidocs/com/spotify/voyager/jni/StringIndex.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>StringIndex (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="declaration: package: com.spotify.voyager.jni, class: StringIndex">
<meta name="generator" content="javadoc/ClassWriterImpl">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Uses of Class com.spotify.voyager.jni.Index.QueryResults (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="use: package: com.spotify.voyager.jni, class: Index, class: QueryResults">
<meta name="generator" content="javadoc/ClassUseWriter">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Uses of Enum com.spotify.voyager.jni.Index.SpaceType (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="use: package: com.spotify.voyager.jni, class: Index, enum: SpaceType">
<meta name="generator" content="javadoc/ClassUseWriter">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Uses of Enum com.spotify.voyager.jni.Index.StorageDataType (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="use: package: com.spotify.voyager.jni, class: Index, enum: StorageDataType">
<meta name="generator" content="javadoc/ClassUseWriter">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Uses of Class com.spotify.voyager.jni.Index (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="use: package: com.spotify.voyager.jni, class: Index">
<meta name="generator" content="javadoc/ClassUseWriter">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!DOCTYPE HTML>
<html lang>
<head>
<!-- Generated by javadoc (17) on Fri Oct 04 14:44:44 EDT 2024 -->
<!-- Generated by javadoc (17) on Wed Oct 16 13:13:57 EDT 2024 -->
<title>Uses of Class com.spotify.voyager.jni.StringIndex.QueryResults (voyager 2.0.10 API)</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="dc.created" content="2024-10-04">
<meta name="dc.created" content="2024-10-16">
<meta name="description" content="use: package: com.spotify.voyager.jni, class: StringIndex, class: QueryResults">
<meta name="generator" content="javadoc/ClassUseWriter">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
Expand Down
Loading

0 comments on commit d68175e

Please sign in to comment.