Excellent question. This is a very practical problem, and the answer depends almost entirely on how you configure llama-cpp to use your hardware.
Let's break it down into a few scenarios, from worst-case to best-case.
Your hardware specs are key:
- Ryzen 5 2600 (CPU): A capable 6-core, 12-thread processor. It will be the bottleneck in the worst-case scenario.
- RTX 2060 (GPU): This is your secret weapon. It has 6 GB of VRAM and Tensor Cores, which are fantastic for AI tasks. Using this GPU correctly is the difference between this task taking days versus taking about an hour.
The model:
- nomic-embed-code: This is a BERT-style model, not a Llama-style LLM. It's relatively small, which is great news for your 6 GB of VRAM. A quantized GGUF version (like Q4_K_M) will be around 500 MB, easily fitting into your GPU's memory.
Scenario 1: Worst Case (CPU Only)
If you download a generic llama-cpp build or compile it without GPU support, it will run entirely on your Ryzen 5 2600.
- How it works: Your CPU will handle all the math. While it has 12 threads, it's vastly slower than a GPU for this kind of parallel work.
- Estimated Speed: You can expect a processing speed of roughly 1 to 5 chunks per second. Let's be optimistic and say 3 chunks/sec on average.
- Calculation: 685,147 chunks / 3 chunks/sec ≈ 228,382 seconds.
- 228,382 / 3600 ≈ 63.4 hours (or about 2.6 days)
Conclusion: Do not run this on CPU only. It's a massive waste of time when you have a perfectly good GPU.
Scenario 2: Best Case (Full GPU Offloading)
This is the correct way to do it. You will compile llama-cpp with NVIDIA CUDA support (cuBLAS) and tell it to offload all the model's layers to your RTX 2060.
- How it works: The small
nomic-embed-code model is loaded entirely into your GPU's VRAM. The RTX 2060's Tensor Cores will process hundreds of chunks in parallel (in batches), making the process incredibly fast. Your CPU will just be feeding data to the GPU.
- Estimated Speed: With full GPU offloading and a decent batch size, you should expect 100 to 300+ chunks per second. Let's use a conservative estimate of 150 chunks/sec.
- Calculation: 685,147 chunks / 150 chunks/sec ≈ 4,567 seconds.
- 4,567 / 60 ≈ 76 minutes (or about 1 hour and 16 minutes)
Conclusion: This is the target. It turns a multi-day job into something you can run while you have lunch.
Summary Table
| Scenario | Primary Processor | Estimated Speed (chunks/sec) | Estimated Total Time |
|---|
| Best Case (Full GPU) | RTX 2060 | 100 - 300+ | ~30 minutes to 1.5 hours |
| Worst Case (CPU Only) | Ryzen 5 2600 | 1 - 5 | ~2.5 days |
How to Achieve the Best-Case Scenario (Action Plan)
Follow these steps to ensure you're using your GPU.
1. Compile llama-cpp with CUDA Support
If you just downloaded a pre-built executable, it might not have CUDA support. It's best to compile it yourself. It's easier than it sounds.
# 1. Clone the repository
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
# 2. Compile with cuBLAS support (This is the magic step for NVIDIA)
# This command tells the build system to find your CUDA toolkit and include it.
make clean
CMAKE_ARGS="-DLLAMA_CUBLAS=1" make
(You'll need the NVIDIA CUDA Toolkit installed on your system for this to work).
2. Use the Right Command-Line Flags
When you run your embedding script, the two most important flags are -ngl (number of GPU layers) and -b (batch size).
-ngl <number>: Tells llama-cpp how many model layers to offload to the GPU. For a small model like nomic-embed-code, you can offload all of them. A common trick is to set a high number like -ngl 99.
-b <number>: Sets the batch size. A larger batch size is more efficient for the GPU. The ideal size depends on your VRAM and chunk size, but start with 512.
3. Example Command
Here is an example of what your llama-cpp command might look like when used for embedding. (This is a conceptual example; your script will call this in a loop).
# This command embeds the text "my code chunk" using the nomic model
# with full GPU offloading and a batch size of 512.
./main -m ./models/nomic-embed-code-v1.5.Q4_K_M.gguf --embedding -p "my code chunk" -ngl 99 -b 512
4. Recommendation: Do a Test Run!
Don't start the full 685k job immediately. Test your setup on a small sample first.
- Take a batch of 10,000 chunks.
- Run the embedding process and time it.
- Let's say it takes 60 seconds.
- You can then extrapolate: (685,147 / 10,000) * 60 seconds ≈ 4110 seconds ≈ 68.5 minutes.
This test will confirm your setup is working correctly and give you a much more accurate estimate for your specific hardware and data.