-
Notifications
You must be signed in to change notification settings - Fork 5
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
7 changed files
with
73 additions
and
2 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
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,44 @@ | ||
defmodule Components.MovespaceDB do | ||
alias TaiShangMicroFaasSystem.Repo | ||
alias Ecto.Adapters.SQL | ||
def create_vector_db_if_uncreated(vector_db_name, size \\ 1536) do | ||
sql_cmd = """ | ||
CREATE TABLE #{vector_db_name} ( | ||
id bigserial PRIMARY KEY, | ||
id_in_embedbase text, | ||
raw_data text, | ||
meta_data JSONB, | ||
embedding vector(#{size})); | ||
""" | ||
SQL.query(Repo, sql_cmd, []) | ||
end | ||
|
||
def insert_vector(vector_db_name, id_in_embedbase, raw_data, meta_data, embedding) do | ||
sql_cmd = """ | ||
INSERT INTO #{vector_db_name} (id_in_embedbase, raw_data, meta_data, embedding) VALUES ( | ||
'#{id_in_embedbase}', | ||
'#{raw_data}', | ||
'#{data_to_sql_string(meta_data)}', | ||
'#{data_to_sql_string(embedding)}'); | ||
""" | ||
SQL.query(Repo, sql_cmd, []) | ||
end | ||
|
||
def data_to_sql_string(nil), do: "null" | ||
def data_to_sql_string(data), do: Poison.encode!(data) | ||
|
||
def search_data_by_id(vector_db_name, id) do | ||
sql_cmd = """ | ||
SELECT * FROM #{vector_db_name} WHERE id = '#{id}'; | ||
""" | ||
SQL.query(Repo, sql_cmd, []) | ||
end | ||
|
||
def search_data_by_indexer_in_embedbase(vector_db_name, id_in_embedbase) do | ||
sql_cmd = """ | ||
SELECT * FROM #{vector_db_name} WHERE id_in_embedbase = '#{id_in_embedbase}'; | ||
""" | ||
SQL.query(Repo, sql_cmd, []) | ||
end | ||
|
||
end |
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 @@ | ||
Postgrex.Types.define(TaiShangMicroFaasSystem.PostgrexTypes, [Pgvector.Extensions.Vector] ++ Ecto.Adapters.Postgres.extensions(), []) |
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 |
---|---|---|
|
@@ -23,7 +23,7 @@ defmodule TaiShangMicroFaasSystem.Users.User do | |
end | ||
|
||
## | ||
## TaiShangMicroFaasSystem.Users.User.create_admin(%{email: "[email protected]", password: "12345678", password_confirmation: "12345678"}) | ||
# TaiShangMicroFaasSystem.Users.User.create_admin(%{email: "[email protected]", password: "12345678", password_confirmation: "12345678"}) | ||
## | ||
@spec create_admin(map()) :: {:ok, t()} | {:error, Ecto.Changeset.t()} | ||
def create_admin(params) do | ||
|
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
11 changes: 11 additions & 0 deletions
11
priv/repo/migrations/20231102100114_create_vector_extension.exs
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,11 @@ | ||
defmodule TaiShangMicroFaasSystem.Repo.Migrations.CreateVectorExtension do | ||
use Ecto.Migration | ||
|
||
def up do | ||
execute "CREATE EXTENSION IF NOT EXISTS vector" | ||
end | ||
|
||
def down do | ||
execute "DROP EXTENSION vector" | ||
end | ||
end |