Tester les embeddings Ollama avec un script Node.js minimal

Semantic search is becoming easier to prototype thanks to lightweight models and tools like Ollama's nomic-embed-text. I wanted to see how well a local solution would perform—without relying on cloud services or heavyweight vector databases.

So I built a tiny Node.js script that:

Here’s what I came up with:


🖥️ Platform Specs


📚 Dataset


⏱️ Embedding Performance

The script reads all posts and sends each one to Ollama for embedding. Total time:

Each embedding was fetched via HTTP from a locally running Ollama instance, so this includes I/O, JSON parsing, and vector serialization.


🔍 Search Performance (In-Memory)

To test semantic search:

  1. A query is embedded using Ollama.
  2. The resulting vector is compared against all post vectors in memory using cosine similarity.
  3. Top 5 posts are returned.

Performance:
21–51 ms per query — even with no indexing.

For small datasets, this is more than fast enough for real-time use, especially with our ERP/CRM/DMS products where users can find matching documents quickly and only few users access the system.


🧠 Replacing the Loop: SQL Vector Search with MemCP

While the Node.js prototype loops through each post in a for loop, that doesn’t scale well. Normally, we’d reach for a vector database like Pinecone, Qdrant, or the upcoming MySQL vector extension to make use of a vector index.

But MySQL’s vector support isn't released yet — so I tried something new: MemCP, an in-memory SQL engine with vector support.

✅ The Goal

Replace this Node.js loop:

for (const post of posts) {
  const distance = cosineSimilarity(queryVector, post.vector);
  // store or rank the result
}

With a SQL query like this:

SELECT ID, post_title, url
FROM posts
ORDER BY VECTOR_DISTANCE(vector, STRING_TO_VECTOR(?)) ASC
LIMIT 5;

🧪 Why MemCP?

🔧 Integration Plan


🏁 Summary

TaskTime / Speed
Embedding 650 posts167,148 ms total
Avg. embedding time/post257 ms
Read+Embed speed~16 KB/s
In-memory vector search21–51 ms per query
SQL vector search (MemCP)(In progress, but promising)

📌 Takeaways

If you’re building internal tools, dashboards, or blog search, this is a surprisingly effective stack—with zero cloud dependencies.

Catégories