diff --git a/apps/api/lib/buildel/blocks/document_search.ex b/apps/api/lib/buildel/blocks/document_search.ex index c603e351c..392085634 100644 --- a/apps/api/lib/buildel/blocks/document_search.ex +++ b/apps/api/lib/buildel/blocks/document_search.ex @@ -58,6 +58,14 @@ defmodule Buildel.Blocks.DocumentSearch do "minimum" => 0.0, "maximum" => 1.0, "step" => 0.01 + }, + metadata: %{ + "type" => "string", + "title" => "Metadata", + "description" => "The metadata of documents to include in retrieval.", + "default" => "{}", + "presentAs" => "editor", + "editorLanguage" => "json" } ) }) diff --git a/apps/api/lib/buildel/memories.ex b/apps/api/lib/buildel/memories.ex index f13445739..573251e4c 100644 --- a/apps/api/lib/buildel/memories.ex +++ b/apps/api/lib/buildel/memories.ex @@ -222,7 +222,7 @@ defmodule Buildel.Memories do def list_organization_memory_chunks( %Organization{id: organization_id}, - %Memory{memory_collection_id: memory_collection_id}, + %Memory{memory_collection_id: memory_collection_id, id: memory_id}, _params \\ %{} ) do vector_db = @@ -239,6 +239,7 @@ defmodule Buildel.Memories do Buildel.VectorDB.get_all( vector_db, "#{organization_id}_#{memory_collection_id}", + %{memory_id: memory_id}, %{} ) end diff --git a/apps/api/lib/buildel/vector_db.ex b/apps/api/lib/buildel/vector_db.ex index 8d459f467..050a78481 100644 --- a/apps/api/lib/buildel/vector_db.ex +++ b/apps/api/lib/buildel/vector_db.ex @@ -76,10 +76,10 @@ defmodule Buildel.VectorDB do results end - def get_all(%__MODULE__{adapter: adapter}, collection_name, _params) do + def get_all(%__MODULE__{adapter: adapter}, collection_name, metadata \\ %{}, params \\ %{}) do {:ok, collection} = adapter.get_collection(collection_name) - adapter.get_all(collection, %{}) + adapter.get_all(collection, metadata, params) end def delete_all_with_metadata(%__MODULE__{adapter: adapter}, collection_name, metadata) do @@ -239,10 +239,10 @@ defmodule Buildel.VectorDB.EctoAdapter do :ok end - def get_all(collection, _params) do + def get_all(collection, metadata, _params) do Buildel.Repo.all( from c in Chunk, - where: c.collection_name == ^collection.name + where: c.collection_name == ^collection.name and fragment("? @> ?", c.metadata, ^metadata) ) |> Enum.map(fn chunk -> %{