Skip to content

Commit 961bd48

Browse files
odysseaspentarobfrank
authored andcommitted
Fixes for a couple of issues discovered with vector support (#2433)
* Fixed a couple of issues with creating a vector index of embeddings and querying the index. * Cleaned-up the test case by using the TestHelper (cherry picked from commit 531fcf6)
1 parent 7fe0f0c commit 961bd48

File tree

4 files changed

+62
-3
lines changed

4 files changed

+62
-3
lines changed

engine/src/main/java/com/arcadedb/query/sql/function/vector/SQLFunctionVectorNeighbors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public Object execute(final Object self, final Identifiable currentRecord, final
6464

6565
final int limit = params[2] instanceof Number n ? n.intValue() : Integer.parseInt(params[2].toString());
6666

67-
final List<Pair<Vertex, ? extends Number>> neighbors = vIndex.findNeighborsFromVector(key, limit, null);
67+
final List<Pair<Vertex, ? extends Number>> neighbors = vIndex.findNeighborsFromId(key, limit, null);
6868

6969
final ArrayList<Object> result = new ArrayList<>(neighbors.size());
7070
for (Pair<Vertex, ? extends Number> n : neighbors)

integration/src/main/java/com/arcadedb/integration/importer/vector/TextEmbeddingsImporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,10 @@ public TextEmbeddingsImporter setContext(final ImporterContext context) {
227227

228228
private List<TextFloatsEmbedding> loadFromFile() throws IOException {
229229
try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
230-
final Stream<String> parser = reader.lines();
230+
Stream<String> parser = reader.lines();
231231

232232
if (settings.parsingLimitEntries > 0)
233-
parser.limit(settings.parsingLimitEntries);
233+
parser = parser.limit(settings.parsingLimitEntries);
234234

235235
final AtomicInteger vectorSize = new AtomicInteger(301);
236236

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.arcadedb.integration.importer;
2+
3+
import com.arcadedb.database.Database;
4+
import com.arcadedb.database.DatabaseFactory;
5+
import com.arcadedb.graph.Vertex;
6+
import com.arcadedb.integration.TestHelper;
7+
import com.arcadedb.query.sql.executor.Result;
8+
import com.arcadedb.query.sql.executor.ResultSet;
9+
import com.arcadedb.utility.FileUtils;
10+
import org.junit.jupiter.api.Test;
11+
12+
import java.io.File;
13+
import java.io.IOException;
14+
import java.util.concurrent.atomic.AtomicInteger;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
public class FastTextVectorImportTest extends com.arcadedb.TestHelper
19+
{
20+
@Test
21+
public void vectorNeighborsQuery() {
22+
database.command("sql", "import database file://src/test/resources/cc.en.300.small.vec.gz " //
23+
+ "with distanceFunction = cosine, m = 16, ef = 128, efConstruction = 128, " //
24+
+ "vertexType = Word, edgeType = Proximity, vectorProperty = vector, idProperty = name" //
25+
);
26+
assertThat(database.countType("Word", true)).isEqualTo(1000);
27+
28+
final ResultSet rs = database.command("SQL",
29+
"select expand(vectorNeighbors('Word[name,vector]','with',10))");
30+
31+
final AtomicInteger total = new AtomicInteger();
32+
while (rs.hasNext()) {
33+
final Result record = rs.next();
34+
assertThat(record).isNotNull();
35+
Vertex vertex = (Vertex) record.getElementProperty("vertex");
36+
Float distance = record.getProperty("distance");
37+
total.incrementAndGet();
38+
}
39+
40+
assertThat(total.get()).isEqualTo(10);
41+
}
42+
43+
@Test
44+
public void parsingLimitEntries() {
45+
database.command("sql", "import database file://src/test/resources/cc.en.300.small.vec.gz " //
46+
+ "with distanceFunction = cosine, m = 16, ef = 128, efConstruction = 128, " //
47+
+ "vertexType = Word, edgeType = Proximity, vectorProperty = vector, idProperty = name, "
48+
+ "parsingLimitEntries = 101"
49+
);
50+
51+
// The header is skipped, so we expect 100 entries
52+
assertThat(database.countType("Word", true)).isEqualTo(100);
53+
}
54+
55+
@Override
56+
protected String getDatabasePath() {
57+
return "target/databases/test-fasttextsmall";
58+
}
59+
}
657 KB
Binary file not shown.

0 commit comments

Comments
 (0)