Sudip Mondal
Sudip Mondal

Reputation: 7

Order by ASC doesn't return any item but order by DESC does

Any known explanation of this? Why Order By ASC doesn't return any item but order by DESC doesn't?

I am using postgres with pg_vector extension

ASC

DESC

SELECT
       langchain_pg_embedding.document,
       langchain_pg_embedding.embedding <=> (ARRAY [-0.021213598549366,  ...,           -0.03685509413480759])::vector AS distance
FROM langchain_pg_embedding
         JOIN langchain_pg_collection
              ON langchain_pg_embedding.collection_id = langchain_pg_collection.uuid
WHERE langchain_pg_embedding.collection_id = '3831f45b-ee1b-4009-afa4-c7b0e1aadda7'
ORDER BY distance DESC
LIMIT 1;

I am expecting in each query I will get one row (but different).

Upvotes: -2

Views: 77

Answers (1)

sheng yan
sheng yan

Reputation: 138

Normally, sorting only affects the order of the result set, not the content of the result set.

If the data is not large, it is recommended to remove limit 1 and see if the total amount of data is correct.

I feel that there is a sort order that causes the results to be null for the first few, and the query tool does not show it.

Upvotes: -3

Related Questions