Ash FrameworkAF
Ash Framework2w ago
9 replies
jannibeu

Vector search example not working

https://github.com/ash-project/ash_ai/blob/cc1105ac8169d280f229d857f353b7856543e07c/usage-rules.md?plain=1#L120

This example does not work

My code
    read :semantic_search do
      argument :query, :string, allow_nil?: false

      prepare before_action(fn query, context ->
        case InterimIq.Embeddings.OpenAiEmbeddingModel.generate([query.arguments.query], []) do
          {:ok, [search_vector]} ->
            Ash.Query.filter(
              query,
              vector_cosine_distance(full_text_vector, ^search_vector) < 1
            )
            |> Ash.Query.sort([
              {
                  vector_cosine_distance(
                    full_text_vector,
                    ^search_vector
                  ),
                :asc
              }

            ])

          {:error, error} ->
            {:error, error}
        end
      end)
    end


My error

error: undefined variable "full_text_vector"
  lib/interim_iq/project_profile_matching/profile.ex:70:21

error: misplaced operator ^search_vector

The pin operator ^ is supported only inside matches or inside custom macros. Make sure you are inside a match or all necessary macros have been required
  lib/interim_iq/project_profile_matching/profile.ex:71:21
GitHub
Structured outputs, vectorization and tool calling for your Ash application - ash-project/ash_ai
ash_ai/usage-rules.md at cc1105ac8169d280f229d857f353b7856543e07c ...
Solution
|> Ash.Query.sort([
  {
      calc(vector_cosine_distance(
        full_text_vector,
        ^search_vector
      )),
    :asc
  }

])
Was this page helpful?