Repository navigation
fix: use column expression in order_by instead of string literal - #7
Merged
daimor merged 2 commits intoDec 9, 2025
Merged
Conversation
The order_by(asc("distance")) call fails because SQLAlchemy requires
a column expression object, not a string literal. This fix extracts
the distance expression to a variable and references it directly in
the order_by clause.
Changes:
- Extract distance_expr before the query
- Use distance_expr in session.query() and order_by()
- Remove unused asc import
- Add regression test for similarity_search_with_score_by_vector
The original test used DeterministicFakeEmbedding which doesn't generate distinguishable embeddings for similarity search. Changed to use FakeEmbeddings (consistent with other tests) and simplified the assertion to verify a document is returned from the collection, matching the pattern used by other tests in the suite.
Contributor
|
May be this issue is also solved in pr #6 |
Member
|
ohh, hey, looks like I'll need to merge both changes |
Member
|
tests working here |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
order_by(asc("distance"))bug where SQLAlchemy requires a column expression object, not a string literaldistance_expr) and used it in bothsession.query()andorder_by()ascimporttest_irisvectortest that was using an incorrect assertion patternProblem
When calling
similarity_search_with_score_by_vector(), the query fails with an error because SQLAlchemy'sorder_by()clause was receiving a string literal"distance"viaasc("distance"), but SQLAlchemy requires an actual column expression object.Solution
Extract the distance expression that is already labeled as
"distance"and reference it directly in theorder_by()clause:Test Plan
test_irisvector_similarity_search_with_score_by_vectorthat directly calls the affected methodtest_irisvectortest to use consistent assertion patternFiles Changed
langchain_iris/vectorstores.py: Fix implementation + removed unusedascimporttests/test_vectorstores.py: Added regression test + fixed pre-existing test