This project implements a two-tower neural network architecture for semantic document search, trained on the MS MARCO dataset.
- Install dependencies:
pip install -r requirements.txt- Start the server:
python src/main.pyThe server will start on http://0.0.0.0:8001.
docker build -t two-tower-network .
# Run the container
docker run -p 8001:8001 two-tower-networkcurl http://localhost:8001/health# Search with default k=1
curl -X POST "http://localhost:8001/query" \
-H "Content-Type: application/json" \
-d '{"query": "how to make coffee"}'
# Search with custom k (e.g., k=3)
curl -X POST "http://localhost:8001/query" \
-H "Content-Type: application/json" \
-d '{"query": "how to make coffee", "k": 3}'This model is trained on the MS MARCO dataset. I wasn't able to push the data or faiss index due to size. To retrain the model or the index, you'll need to preprocess the dataset first:
-
Create training triplets:
- For each query, extract the positive passage (is_selected=1) and randomly sample negative passages
- Format: (query, positive passage text, negative passage text)
- Save as
data/train_triplets.parquetanddata/validation_triplets.parquet
-
Create document index:
- Extract all unique passages into a single file
- Save as
data/unique_documents.parquet
The system uses a two-tower architecture:
- Tower One: Encodes queries
- Tower Two: Encodes documents
- Both towers project inputs into the same embedding space
- FAISS is used for efficient similarity search