- Published on
Adding cool search to my blog. Part 2
- Author
- Illia Vasylevskyi
My blog search system was really simple using two-sided LIKE on title, so let's create cool site search using ML and Python.
You can find code in repository github.com/ineersa/blog-search
After we finished with basic development, we need to serve our search service.
For this purpose we will setup venv
on a server
python3 -m venv ~/search-venv
source ~/search-venv/bin/activate
Now we can install dependencies
pip install -r requirements.txt
To generate embdeddings we need to execute commands step by step:
python -m commands.1_read
python -m commands.2_split
python -m commands.3_embed
First command will read unprocessed documents from database (must setup connection in .env).
Second command will split documents to searchable chunks.
Third command will generate embeddings and store them in local database for future usage.
To serve API for our service we will use a simple service definition:
sudo nano /etc/systemd/system/search.ineersa.com.service
[Unit]
Description=Search Service
After=syslog.target network.target mysql.service
[Service]
User=root
Group=root
Type=simple
Restart=on-failure
RestartSec=50s
LimitNOFILE=4096
PIDFile=/run/search.ineersa.com.pid
StandardOutput=journal
StandardError=inherit
Environment="PATH=/root/search-venv/bin"
ExecStart=/root/search-venv/bin/uvicorn main:app --host 127.0.0.1 --port 3335 --workers 1 --proxy-headers
WorkingDirectory=/var/www/search.ineersa.com
[Install]
WantedBy=multi-user.target
Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload
Start the service:
sudo systemctl start search.ineersa.com.service
Enable the service to start on boot:
sudo systemctl enable search.ineersa.com.service
To check the status of service and ensure it’s running correctly:
sudo systemctl status search.ineersa.com.service
To check service logs you can go to syslog or use:
journalctl -u search.ineersa.com.service
journalctl -u search.ineersa.com.service -f
journalctl -u search.ineersa.com.service --since today