|
| 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 | +} |
0 commit comments