ai

Omar 2025-06-29T10:04:03.386459Z

There any way to create embeddings locally from clojure? I currently have a small python script spun up using huggingface bge-large model that is responding to local http requests to provide me this, and of course dealing with python version/dependencies on an old VPS was the most difficult part of the task.

usametov 2025-06-30T13:39:31.824749Z

Local embedding models, such as All-MiniLM-L6-v2, are not suitable for most cases. But this is a continuously changing landscape, so please check the MTEB leaderboard on Hugging Face. For my last project, I used the Gemini Embedding API from Google. This is significantly better than running local models on OLLAMA in terms of accuracy and speed. And it is free.

💡 1
oλv 2025-06-30T13:42:07.551809Z

LM Studio is super convenient for experimenting with local LLMs and embedding models :^)

👀 1
oλv 2025-06-30T14:03:25.572149Z

Dropping the link: https://lmstudio.ai/ It implements the OpenAI API for embeddings and completions so you can use it with https://github.com/wkok/openai-clojure or whatever

🙏 1
Omar 2025-06-30T18:04:27.230979Z

Datalevin is ~10x faster than langchain4j for my 1024 dimension vector search across 1088 embeddings

(let [q "patrol or camry"]
    (encore/qb 5
               (l4j-query q 10) ; langchain4j
               (top-k (user-query->embed q) 10) ; naive implementation
               (d/search-vec index (user-query->embed q) {:top 10}) ; datalevin
               ))
  ;; => [8.41 56.79 0.74] 

😯 1
oλv 2025-06-29T11:38:56.015479Z

Yup can avoid the network barrier by using libpython-clj at least

Daniel Slutsky 2025-06-29T15:39:34.311099Z

Hi. Here are a few resources demonstrating the use of LangChain4J to create embeddings in Clojure. A tutorial by @carsten.behring: https://scicloj.github.io/clojure-data-tutorials/projects/ml/llm/vectorstore.html A session we had at the Scicloj AI group: https://www.youtube.com/watch?v=fvcnCxFHyos The recent talk (and detailed notes) by @eoincarney0 at the SciNoj Light #1 conference: https://scicloj.github.io/scinoj-light-1/sessions.html#parliamentary-questions-and-answers-using-noj-to-explore-basic-rag-techniques I think LangChain4J supports different kinds of embeddings, and I haven't explored their diversity.

Omar 2025-06-29T16:22:15.816829Z

Oh very cool! Yesterday implemented a RAG for car search on a classified site without exploring this space previously and it's working very well despite having no knowledge. Thanks Daniel for all the material to pour over!

🙏 1
oλv 2025-06-29T16:44:51.666459Z

Have you tried the Datalevin similarity search features?

💡 1
oλv 2025-06-29T16:45:35.988879Z

It's pretty sweet for doing RAG in Clojure 🤓

Omar 2025-06-29T18:49:18.776939Z

Haven't heard of Datalevin before, I'm pretty slow at picking up new things, like to let them mature a bit. Only thing I ever adopted extremely early was malli.

Omar 2025-06-29T22:17:12.362539Z

Just typing some comments here: I tried the latest lang4j, its API changed quite a bit since the meetup video in the most awkward ways. The embedding store works faster than my naive clojure implementation bring search down from 25ms to 5ms for 1088 embeddings of 1024 dimensions. The 384 dimension embeddings from AllMiniLmL6V2EmbeddingModel are significantly worse than my python script's model BAAI/bge-large-en-v1.5 returning flat out wrong makes/models when the bigger model correctly infers things. Will try an embedded datalevin vector search next and libpython-clj so I can easily use the latest models.

Daniel Slutsky 2025-06-29T22:23:28.767589Z

Oh, that is so helpful to know.

Daniel Slutsky 2025-06-29T22:24:20.199879Z

This seems to be the list of embedding models supported: https://github.com/langchain4j/langchain4j-embeddings

Omar 2025-06-29T22:25:22.106649Z

Yeha I saw that, I asked gpt4.1 about them and they all seem worse than the bge-large model. The bge-large model takes about 100ms to make an embedding via python which isn't bad, I was getting 1-2 seconds using open AI's API.

👍 1
Omar 2025-06-29T22:25:42.779219Z

I didn't notice any drop of quality of results either

Omar 2025-06-29T22:29:11.715959Z

in case you're interested, can try it out here by prefixing search query by "i want " https://sayartii.com/ Nearly all the latency is coming from calling gpt4.1mini to process the results and return JSON.

👍 1
Omar 2025-06-29T22:30:07.147289Z

I saw somewhere that azure has 4.1mini and is faster.

Daniel Slutsky 2025-06-29T22:31:08.667699Z

Thanks

Omar 2025-06-29T22:36:06.746269Z

Planning on making a chatbot RAG at some point soon to ask probing questions and get extra debug information from people when they post repair requests like this https://motorsaif.com/requests/tct-892 then augment the description with that summary.

👍 1
Daniel Slutsky 2025-06-29T22:40:58.292279Z

There seems to be a Java wrapper for various embedding services: https://howtodoinjava.com/spring-ai/vector-embedding-example/ https://docs.spring.io/spring-ai/reference/api/embeddings.html I've never tried it, and don't know whether it makes seems easier or more stable compared to using the bridge to Python.

Omar 2025-06-29T22:48:13.474159Z

It looks like those just call the API which is trivial to do with clojure http.

(defn embed-text [text]
  (let [res (http/post ""
                       {:headers {"Authorization" (str "Bearer " open-api-key)
                                  "Content-Type"  "application/json"}
                        :body    (json/encode {:model "text-embedding-3-small"
                                               :encoding_format "base64"
                                               :input text})})
        body (-> res
                 :body
                 json/decode)
        base64-embedding (get-in body ["data" 0 "embedding"])]
    (decode-b64-embedding base64-embedding)))

Omar 2025-06-29T22:49:10.547429Z

The python one I'm using runs locally, provides 1024 dimension embeddings fairly quickly.

👍 1
➕ 1
Daniel Slutsky 2025-06-29T22:55:10.657939Z

Yes. Some of those APIs, such as Ollama, can be run locally, and may have good embedding models in their collection (and indeed should be easy to be accessed directly from Clojure). Anyway, the Python way sounds good.

Omar 2025-06-29T23:00:04.313669Z

Yup just got libpython-clj working, shaves ~200ms off 20 consecutive runs from the flask http version. Really cool!

🚀 1
✨ 1
christos 2025-07-07T14:45:17.167169Z

you can also use onnx models directly in langchain4j, and at the very least any python model can be exported to onnx

🙏 1
christos 2025-07-07T14:47:53.205389Z

I am doing something like the following