File tree Expand file tree Collapse file tree 2 files changed +6
-2
lines changed
Expand file tree Collapse file tree 2 files changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -55,7 +55,11 @@ def index
5555
5656 if params [ :similar_to ] . present?
5757 embedding = get_embedding ( params [ :similar_to ] )
58- @documents = related_documents_from_embedding_by_libraries ( embedding , library_id )
58+ # Get similar documents but preserve existing filters
59+ similar_docs = related_documents_from_embedding_by_libraries ( embedding , library_id )
60+ # Apply the similarity search as an additional filter by getting the IDs
61+ similar_doc_ids = similar_docs . pluck ( :id )
62+ @documents = @documents . where ( id : similar_doc_ids )
5963 end
6064
6165 @documents = @documents . search_by_title_and_document ( params [ :contains ] ) if params [ :contains ] . present?
Original file line number Diff line number Diff line change @@ -14,6 +14,6 @@ def related_documents_from_embedding(embedding)
1414 def related_documents_from_embedding_by_libraries ( _embedding , _library_ids )
1515 scope = related_documents_from_embedding ( _embedding )
1616 scope = scope . where ( library_id : _library_ids ) if _library_ids . present?
17- scope . order ( created_at : :desc ) . limit ( 100 )
17+ scope . order ( updated_at : :desc ) . limit ( 100 )
1818 end
1919end
You can’t perform that action at this time.
0 commit comments