Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
leeduckgo committed Nov 8, 2023
1 parent 4a246fa commit 38991fd
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ config :tai_shang_micro_faas_system, TaiShangMicroFaasSystemWeb.Endpoint,
pubsub_server: TaiShangMicroFaasSystem.PubSub,
live_view: [signing_salt: "mbnVB7Pw"]

# vectorDB config
config :tai_shang_micro_faas_system, TaiShangMicroFaasSystem.Repo, types: TaiShangMicroFaasSystem.PostgrexTypes
# Authentication
config :tai_shang_micro_faas_system, :pow,
user: TaiShangMicroFaasSystem.Users.User,
Expand Down
44 changes: 44 additions & 0 deletions lib/components/movespace_db.ex
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
1 change: 1 addition & 0 deletions lib/postgrex_types.ex
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(), [])
2 changes: 1 addition & 1 deletion lib/tai_shang_micro_faas_system/users/user.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ defmodule TaiShangMicroFaasSystem.MixProject do
compilers: [:gettext] ++ Mix.compilers(),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
deps: deps(),
description: "micro faas impl with elixir",
]
end

defp package do

Check warning on line 18 in mix.exs

View workflow job for this annotation

GitHub Actions / test

function package/0 is unused

Check warning on line 18 in mix.exs

View workflow job for this annotation

GitHub Actions / test

function package/0 is unused

Check warning on line 18 in mix.exs

View workflow job for this annotation

GitHub Actions / test

function package/0 is unused

Check warning on line 18 in mix.exs

View workflow job for this annotation

GitHub Actions / test

function package/0 is unused
[
files: ["lib", "mix.exs", "README.md"],
maintainers: ["skyblue"],
licenses: ["Apache 2.0"],
links: %{"GitHub" => "https://github.com/NonceGeek/tai_shang_micro_faas_system"}
]
end

Expand Down Expand Up @@ -85,6 +95,8 @@ defmodule TaiShangMicroFaasSystem.MixProject do
# vector dataset interactor
{:embedbase_ex, "~> 0.1.0"},

# pgVector
{:pgvector, "~> 0.2.0"},
# renamer
{:rename_project, "~> 0.1.0", only: :dev},
]
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"nimble_pool": {:hex, :nimble_pool, "1.0.0", "5eb82705d138f4dd4423f69ceb19ac667b3b492ae570c9f5c900bb3d2f50a847", [:mix], [], "hexpm", "80be3b882d2d351882256087078e1b1952a28bf98d0a287be87e4a24a710b67a"},
"paginator": {:hex, :paginator, "1.1.0", "e502a91b08d14a6c8319f86eae027e67b0c699ffca4d76afbcb43eea5f32cd53", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "b484f533b4a157ff60df7c988c9ef04e9c64e1f96e74a48a700717517a1ba5d9"},
"parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"},
"pgvector": {:hex, :pgvector, "0.2.1", "dc707ce6065ac0e82e5716bc17f9c6a97f92aca23994e5cceef7dfc48bb57eed", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:nx, "~> 0.5", [hex: :nx, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.0.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "ed86c560af2f85b31d79f119192ce98f3342b4d06ceac63824a8686fe07e59b6"},
"phoenix": {:hex, :phoenix, "1.6.11", "29f3c0fd12fa1fc4d4b05e341578e55bc78d96ea83a022587a7e276884d397e4", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1664e34f80c25ea4918fbadd957f491225ef601c0e00b4e644b1a772864bfbc2"},
"phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"},
"phoenix_html": {:hex, :phoenix_html, "3.2.0", "1c1219d4b6cb22ac72f12f73dc5fad6c7563104d083f711c3fcd8551a1f4ae11", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "36ec97ba56d25c0136ef1992c37957e4246b649d620958a1f9fa86165f8bc54f"},
Expand Down
11 changes: 11 additions & 0 deletions priv/repo/migrations/20231102100114_create_vector_extension.exs
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

0 comments on commit 38991fd

Please sign in to comment.