Next to the search bar is a space that says 'Restrict to'. I have not needed to use it so far, but if I understood correctly, restriction works like sub-library - all operations you do will be applied only to that restricted part (like, if you restrict to 'Romance' and then search for Asimov, you won't find anything).
I think this should work:
1. select a library
2. apply a tag (with library name maybe) to all the books
3. copy all books to the main library
4. search for the new tag
5. save that search and name it with library name
I myself lean rather heavily into custom columns (+ some coloring) so I would have probably just made a new 'Library' or 'Category' column.
Tried, but couldn't imagine why I should need several libraries - exept for testing different setups.