QdrantSearch: Support pagination.

This commit is contained in:
Lain Soykaf 2024-05-19 14:41:05 +04:00
parent dbaab6f54e
commit 1b4f1db9b2
1 changed files with 8 additions and 4 deletions

View File

@ -54,10 +54,11 @@ defp build_index_payload(activity, embedding) do
} }
end end
defp build_search_payload(embedding) do defp build_search_payload(embedding, options) do
%{ %{
vector: embedding, vector: embedding,
limit: 20 limit: options[:limit] || 20,
offset: options[:offset] || 0
} }
end end
@ -96,12 +97,15 @@ def remove_from_index(object) do
end end
@impl true @impl true
def search(_user, query, _options) do def search(_user, query, options) do
query = "Represent this sentence for searching relevant passages: #{query}" query = "Represent this sentence for searching relevant passages: #{query}"
with {:ok, embedding} <- get_embedding(query), with {:ok, embedding} <- get_embedding(query),
{:ok, %{body: %{"result" => result}}} <- {:ok, %{body: %{"result" => result}}} <-
QdrantClient.post("/collections/posts/points/search", build_search_payload(embedding)) do QdrantClient.post(
"/collections/posts/points/search",
build_search_payload(embedding, options)
) do
ids = ids =
Enum.map(result, fn %{"id" => id} -> Enum.map(result, fn %{"id" => id} ->
Ecto.UUID.dump!(id) Ecto.UUID.dump!(id)