Skip to content

Commit af1354a

Browse files
committed
chore: migrate from Docker Compose to embedded ChromaDB and add HuggingFace Dockerfile
1 parent 91e4a5e commit af1354a

5 files changed

Lines changed: 28 additions & 17 deletions

File tree

‎Dockerfile‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM python:3.10-slim
2+
3+
WORKDIR /app
4+
5+
# Install dependencies
6+
COPY requirements.txt .
7+
RUN pip install --no-cache-dir -r requirements.txt
8+
9+
# Copy source code
10+
COPY . .
11+
12+
# Generate Embeddings and build the embedded ChromaDB index during the Docker build
13+
RUN python embed.py
14+
RUN python insert_vectors.py
15+
16+
# Expose Hugging Face Space default port
17+
EXPOSE 7860
18+
19+
# Run FastAPI server
20+
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]

‎docker-compose.yml‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎insert_vectors.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def insert_vectors():
3030
print(f"Connecting to ChromaDB at {BASE_URL}:{PORT}...")
3131

3232
try:
33-
# 1. Initialize ChromaDB Client
34-
client = chromadb.HttpClient(host=BASE_URL, port=PORT)
33+
# 1. Connect to Embedded ChromaDB
34+
print("Connecting to local ChromaDB...")
35+
client = chromadb.PersistentClient(path="./chroma_db")
3536

3637
# 2. Ensure index exists
3738
dimension = embeddings.shape[1]

‎search.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
def search_chroma(query):
1515
try:
1616
# 1. Initialize ChromaDB Client
17-
client = chromadb.HttpClient(host=BASE_URL, port=PORT)
17+
# Connect to Embedded ChromaDB
18+
print("Connecting to local ChromaDB...")
19+
client = chromadb.PersistentClient(path="./chroma_db")
1820

1921
# 2. Get the collection
2022
collection = client.get_collection(name=COLLECTION_NAME)

‎server.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ def search(payload: SearchQuery):
4141
# Encode Query
4242
query_vector = model.encode([payload.query])[0].tolist()
4343

44-
client = chromadb.HttpClient(host=BASE_URL, port=PORT)
44+
# Initialize Persistent ChromaDB Client
45+
client = chromadb.PersistentClient(path="./chroma_db")
4546
collection = client.get_collection(name=COLLECTION_NAME)
4647

4748
results_db = collection.query(

0 commit comments

Comments
 (0)