Skip to content

Commit

Permalink
Add memory_id filtering in chunks :D
Browse files Browse the repository at this point in the history
  • Loading branch information
michalwarda committed Feb 24, 2024
1 parent dbf1d77 commit 0f8ab38
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 8 additions & 0 deletions apps/api/lib/buildel/blocks/document_search.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
)
})
Expand Down
3 changes: 2 additions & 1 deletion apps/api/lib/buildel/memories.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -239,6 +239,7 @@ defmodule Buildel.Memories do
Buildel.VectorDB.get_all(
vector_db,
"#{organization_id}_#{memory_collection_id}",
%{memory_id: memory_id},
%{}
)
end
Expand Down
8 changes: 4 additions & 4 deletions apps/api/lib/buildel/vector_db.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ->
%{
Expand Down

0 comments on commit 0f8ab38

Please sign in to comment.