Part 03AI & Infrastructure

Setting Up the Test Environment

A GPU-accelerated embedding engine, Redis with vector search, and a live LLM connection — production-ready infrastructure from scratch.

May 4, 2026·12 min read·Updated

In the previous part I shared my test environment and hypotheses. In this part we put theory into practice: install every component from scratch and verify all connections work.

By the end you'll have a GPU-accelerated embedding engine, a Redis instance capable of vector search, and a real LLM connection.

Installation Order

Order matters. Core tools first, then the database, finally the Python environment. This avoids dependency conflicts.

  1. 01
    Homebrew
    package manager
  2. 02
    Python 3.11+
    runtime
  3. 03
    Docker Desktop
    containerization
  4. 04
    Redis Stack
    cache + vector DB
  5. 05
    Python venv
    isolation
  6. 06
    Libraries
    pip install
  7. 07
    Connection Test
    verification
01package manager

Homebrew

Open Terminal (Cmd + Space → "Terminal") and check whether it's already installed:

terminalbash
$ brew --version

If not installed:

terminalbash
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
You'll be asked for your password — admin privileges required. Takes 2-5 minutes.
02runtime

Python 3.11+

First check the current version:

terminalbash
$ python3 --version

If you have Python 3.10 or above, continue. Otherwise:

terminalbash
$ brew install python@3.11
03containerization

Docker Desktop

We'll run Redis Stack in a container. Check if Docker is installed:

terminalbash
$ docker --version

If not, download the Apple Silicon version from Docker's official site, open the .dmg and drag it into Applications. Verify:

terminalbash
$ docker run hello-world
If you see "Hello from Docker!" you're ready.
04cache + vector DB

Redis Stack

Redis Stack adds the RediSearch and RedisJSON modules on top of classic Redis. Both key-value caching and vector similarity search run from a single container.

terminalbash
$ docker run -d \
  --name redis-stack \
  -p 6379:6379 -p 8001:8001 \
  -v redis-data:/data \
  redis/redis-stack:latest

Port 6379 is where our Python script will connect. Port 8001 is the RedisInsight UI — visit http://localhost:8001 to watch cache entries fill up live.

Verify the container is running:

terminalbash
$ docker exec -it redis-stack redis-cli ping

If you see "PONG", Redis is ready. Useful commands:

useful commandsbash
$ docker stop redis-stack
$ docker start redis-stack
$ docker logs redis-stack -f
05isolation

Python venv

Create the project folder and activate the venv:

terminalbash
$ mkdir ~/semantic-cache-lab && cd ~/semantic-cache-lab
$ python3 -m venv venv
$ source venv/bin/activate
If you see (venv) at the start of your terminal prompt, you're in the isolated environment.
06pip install

Libraries

With venv active, create a requirements.txt file:

requirements.txt
openai>=1.0.0
sentence-transformers>=2.7.0
torch>=2.0.0
redis>=5.0.0
tiktoken>=0.7.0
pypdf>=4.0.0
langchain>=0.2.0
langchain-community>=0.2.0
pandas>=2.0.0
matplotlib>=3.8.0
python-dotenv>=1.0.0
tqdm>=4.0.0

Then install:

terminalbash
$ pip install -r requirements.txt

sentence-transformers and torch are large packages — 5-15 minutes depending on your connection. On M-series Macs, MPS support is auto-detected.

Verify MPS is active:

terminalpython
$ python3 -c "import torch; print('MPS:', torch.backends.mps.is_available())"
If you see True, embedding computations will run on the Apple GPU — 3-5x faster than CPU.
07verification

Connection Test

First create the .env file (get your OpenRouter API key from openrouter.ai/keys):

.envenv
OPENROUTER_API_KEY=sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LLM_MODEL=google/gemini-2.0-flash-lite-001
REDIS_HOST=localhost
REDIS_PORT=6379
Never commit .env to git. Add to .gitignore:
.gitignore
.env
venv/
__pycache__/
data/
results/

Then run the test script.

When handling OpenRouter responses, choices is a list — access response.choices[0].message.content with an index.
Expected output
==================================================
CONNECTION TEST
==================================================

[1/4] Redis connection...
✓ Redis: OK

[2/4] Loading embedding model...
✓ Embedding: OK (dim=384, device=mps)

[3/4] OpenRouter LLM connection...
✓ OpenRouter: OK
Response: Yes!
Token usage: 27

[4/4] Token counting...
✓ tiktoken: OK
"This is a test sentence." = 6 tokens

==================================================
ALL CONNECTIONS SUCCESSFUL
==================================================
Up Next

Part 4: Building the RAG Pipeline

Infrastructure is ready. In Part 4 we chunk the WEF report, load it into Redis as vectors, and run our first semantic searches.

Edit this pageLast updated: May 4, 2026