-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
bin/ | ||
obj/ | ||
TestResults/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
Imports Microsoft.VisualStudio.TestTools.UnitTesting | ||
Imports Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert | ||
Imports Npgsql | ||
|
||
Namespace Pgvector.VisualBasic.Tests | ||
<TestClass> | ||
Public Class NpgsqlTests | ||
<TestMethod> | ||
Sub TestSub() | ||
Dim connString = "Host=localhost;Database=pgvector_dotnet_test" | ||
|
||
Dim dataSourceBuilder As New NpgsqlDataSourceBuilder(connString) | ||
dataSourceBuilder.UseVector() | ||
Dim dataSource = dataSourceBuilder.Build() | ||
|
||
Dim conn = dataSource.OpenConnection() | ||
|
||
Using cmd As New NpgsqlCommand("CREATE EXTENSION IF NOT EXISTS vector", conn) | ||
cmd.ExecuteNonQuery() | ||
End Using | ||
|
||
conn.ReloadTypes() | ||
|
||
Using cmd As New NpgsqlCommand("DROP TABLE IF EXISTS vb_items", conn) | ||
cmd.ExecuteNonQuery() | ||
End Using | ||
|
||
Using cmd As New NpgsqlCommand("CREATE TABLE vb_items (id serial PRIMARY KEY, embedding vector(3))", conn) | ||
cmd.ExecuteNonQuery() | ||
End Using | ||
|
||
Using cmd As New NpgsqlCommand("INSERT INTO vb_items (embedding) VALUES ($1), ($2), ($3)", conn) | ||
Dim embedding1 As New Vector(New Single() {1, 1, 1}) | ||
Dim embedding2 As New Vector(New Single() {2, 2, 2}) | ||
Dim embedding3 As New Vector(New Single() {1, 1, 2}) | ||
cmd.Parameters.AddWithValue(embedding1) | ||
cmd.Parameters.AddWithValue(embedding2) | ||
cmd.Parameters.AddWithValue(embedding3) | ||
cmd.ExecuteNonQuery() | ||
End Using | ||
|
||
Using cmd As New NpgsqlCommand("SELECT * FROM vb_items ORDER BY embedding <-> $1 LIMIT 5", conn) | ||
Dim embedding As New Vector(New Single() {1, 1, 1}) | ||
cmd.Parameters.AddWithValue(embedding) | ||
|
||
Using reader As NpgsqlDataReader = cmd.ExecuteReader() | ||
Dim ids As New List(Of Integer) | ||
Dim embeddings As New List(Of Vector) | ||
|
||
While reader.Read() | ||
ids.Add(reader.GetValue(0)) | ||
embeddings.Add(reader.GetValue(1)) | ||
End While | ||
|
||
CollectionAssert.AreEqual(new Integer() {1, 3, 2}, ids.ToArray()) | ||
CollectionAssert.AreEqual(new Single() {1, 1, 1}, embeddings(0).ToArray()) | ||
CollectionAssert.AreEqual(new Single() {1, 1, 2}, embeddings(1).ToArray()) | ||
CollectionAssert.AreEqual(new Single() {2, 2, 2}, embeddings(2).ToArray()) | ||
End Using | ||
End Using | ||
|
||
Using cmd As New NpgsqlCommand("CREATE INDEX ON vb_items USING hnsw (embedding vector_l2_ops)", conn) | ||
cmd.ExecuteNonQuery() | ||
End Using | ||
End Sub | ||
End Class | ||
End Namespace |
22 changes: 22 additions & 0 deletions
22
tests/Pgvector.VisualBasic.Tests/Pgvector.VisualBasic.Tests.vbproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<RootNamespace>Pgvector.VisualBasic.Tests</RootNamespace> | ||
<TargetFramework>net8.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4" /> | ||
<PackageReference Include="MSTest.TestFramework" Version="3.0.4" /> | ||
<PackageReference Include="coverlet.collector" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Pgvector\Pgvector.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |