r/Clojure • u/phronmophobic • Feb 28 '24
Cloogle - Search across half a million clojure functions
https://cloogle.phronemophobic.com/doc-search.html3
2
u/DefiantAverage1 Feb 28 '24
So cool! How does this work?
10
u/phronmophobic Feb 28 '24
The data comes from dewey which locates and indexes clojure libraries on github.
Embeddings are calculated for all vars with doc strings using openai's embedding API (I also tried using https://huggingface.co/BAAI/bge-large-en-v1.5 which can run locally, but calculating embeddings without a GPU is too slow).
All the embeddings are stored in a vector database.
The vector db is searched for each query.
The undocumented code for cloogle is on github.
I also have a blog post that's not specifically about cloogle, but explains the ideas behind semantic search, https://phronmophobic.github.io/clip.clj/semantic-image-search-with-clojure/.
1
1
u/TheLastSock Feb 29 '24
Does cloogle have an API?
2
u/phronmophobic Feb 29 '24
Not currently, but I might be open to the idea depending on what you're looking for. It's also possible to run everything locally (although the setup isn't yet documented).
I would welcome a github issue if you have any thoughts on what an API might look like, https://github.com/phronmophobic/cloogle/issues.
1
u/kakamiokatsu Feb 29 '24
Really cool tool! I've done a quick test:
Searching for sigmoid returns all unrelated results
Searching for sigmoid function returns exactly what I was looking for (but it's a perfect match with the doc string)
2
u/phronmophobic Feb 29 '24
Yes, I've noticed it sometimes struggles with single word queries (which seems to be most searches). It seems to be a limitation of the embeddings that I'm using. I'm still considering what to do about it.
1
u/kakamiokatsu Mar 01 '24
Might be worth to put a temporary simple warning when searching for a single word; if I'd known about that limitation I'd surely added more context to the search.
Nevertheless, awesome tool! I really like it!
1
u/phronmophobic Mar 01 '24
I have since added a "Tip" banner at the top of the page, but it seems like most searches are still 1-2 words. Ultimately, I think it would be easier to improve results for short queries than to change human nature.
1
u/jumar Mar 01 '24
A nice project.
I think it would be useful if it could distinguish libraries from systems/applications (such as toy projects, real open source systems (e.g. Metabase), etc.)
2
u/phronmophobic Mar 01 '24
That seems like an interesting idea. Could you give a few more details about why or how that feature would be used? Also, do have an idea how that might be implemented?
Currently, all the functions are from github so I've been thinking it would be nice to display the star count or maybe some other metrics that indicates the "prestige" of a repo.
2
u/jumar Mar 01 '24
My basic need would be to filter out the noise. When looking for a function, I may not care (much) about occurrences in systems as opposed to libraries.
I guess having a way to rank/order them based on different preferences (stars, libraries vs systems / examples, recent activity, etc) would be useful.
Unfortunately, I don't have a good idea of how this could be implemented in an automated fashion - popular examples could be manually annotated and then perhaps some heuristic (searching for "library" in description :-D)?
1
1
u/Liistrad Feb 28 '24
This is awesome! It already helped me find a bunch of mail libraries by searching for the function names I expect them to have.
4
u/smgun Feb 28 '24
I love it. Bookmarked!
Would be nice to have the core libs functions as well