Skip to content

Commit

Permalink
Handle Pgvector itself in new/1 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
nallwhy authored Sep 3, 2023
1 parent cffb871 commit 0207fcb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pgvector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ defmodule Pgvector do
defstruct [:data]

@doc """
Creates a new vector from a list or tensor
Creates a new vector from a Pgvector or list or tensor
"""
def new(%Pgvector{} = pgvector) do
pgvector
end

def new(list) when is_list(list) do
dim = list |> length()
bin = for v <- list, into: "", do: <<v::float-32>>
Expand Down
5 changes: 5 additions & 0 deletions test/pgvector_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
defmodule PgvectorTest do
use ExUnit.Case

test "pgvector" do
pgvector = Pgvector.new([1, 2, 3])
assert pgvector == pgvector |> Pgvector.new()
end

test "list" do
list = [1.0, 2.0, 3.0]
assert list == list |> Pgvector.new() |> Pgvector.to_list()
Expand Down

0 comments on commit 0207fcb

Please sign in to comment.