create or replace function match_documents_langchain(
  query_embedding vector(768),
  match_count int default 5
)
returns table (
  id uuid,
  content text,
  metadata json,
  similarity float
)
language plpgsql
as $$
begin
  return query
  select
    documents.id,
    documents.content,
    documents.metadata,
    1 - (documents.embedding <=> query_embedding) as similarity
  from documents
  order by documents.embedding <=> query_embedding
  limit match_count;
end;
$$;