Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c6d6e43
feat: Basic revese proxy for pdr_processor_service with nginx
MingJ7 Jun 24, 2025
8e8e190
feat: added proxy for both chat and extractor service
MingJ7 Jun 24, 2025
4691d96
feat: added proxy headers
MingJ7 Jun 25, 2025
e41d0e1
fix: remove host port mapping to improve security
MingJ7 Jun 25, 2025
af26fed
refactor: append _service to pdf_extractor to align it with other ser…
MingJ7 Jun 25, 2025
3758353
chore: Version control chroma docker image in docker-compose.yml
ldw129 Jun 25, 2025
7689cd6
chore: Remove unnecessary commented-out code and comments
ldw129 Jun 25, 2025
16455fe
fix: Add sentence-transformers package into requirements.txt for feat…
ldw129 Jun 25, 2025
003734f
Merge branch 'dev' into feat/nginx_service
MingJ7 Jun 25, 2025
9fe19a8
refactor: Modify HTTPException error messages for server-side security
ldw129 Jun 25, 2025
7174bd4
feat: Strip prefix before proxying to fastapi
MingJ7 Jun 25, 2025
b35374e
feat: Simplify the rewrite directives by adding a trailing slash
MingJ7 Jun 25, 2025
bf5fc48
Merge pull request #77 from ldw129/feat/pdf_embedder_service
NotYuSheng Jun 25, 2025
589f46c
feat: changed nginx image from stable to latest version (1.29.0-apline)
MingJ7 Jun 26, 2025
cb958df
refactor: changed nginx proxy url to match service name without _service
MingJ7 Jun 26, 2025
17f19a6
fix: changed nginx server internal port to be 8080, as per documentation
MingJ7 Jun 26, 2025
a9878d1
Merge branch 'dev' into feat/nginx_service
MingJ7 Jun 26, 2025
0158553
Merge pull request #73 from NotYuSheng/feat/nginx_service
NotYuSheng Jun 26, 2025
b130611
docs: add nginx container name
NotYuSheng Jun 26, 2025
3eb70d9
refactor: change from nginx_service to nginx
NotYuSheng Jun 26, 2025
57bfcad
Merge pull request #78 from NotYuSheng/docs/define-nginx-container-name
NotYuSheng Jun 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chat_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
level=logging.INFO, format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)

app = FastAPI()
app = FastAPI(root_path="/chat")

app.include_router(health.router)
app.include_router(chat.router)
28 changes: 18 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ services:
context: .
dockerfile: ./pdf_processor_service/Dockerfile
container_name: pdf_processor_service
ports:
- "8000:8000"
env_file:
- ./pdf_processor_service/.env

Expand All @@ -14,18 +12,14 @@ services:
context: .
dockerfile: ./chat_service/Dockerfile
container_name: chat_service
ports:
- "8001:8000"
env_file:
- ./chat_service/.env
pdf_extraction:

pdf_extraction_service:
build:
context: .
dockerfile: ./pdf_extraction_service/Dockerfile
container_name: pdf_extraction_service
ports:
- "8002:8000"
depends_on:
- minio

Expand All @@ -40,7 +34,21 @@ services:
- ./embedder_service/.env
depends_on:
- chromadb


nginx:
container_name: nginx
build:
context: .
dockerfile: ./nginx/Dockerfile
ports:
- "80:8080"
env_file:
- ./nginx/.env
depends_on:
- pdf_extraction_service
- pdf_processor_service
- chat_service

redis:
container_name: redis
image: redis:7.4.4-alpine
Expand All @@ -49,7 +57,7 @@ services:

chromadb:
container_name: chromadb
image: chromadb/chroma:1.0.14
image: chromadb/chroma:1.0.13

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The chromadb/chroma image is being downgraded from 1.0.14 to 1.0.13. While this might be intentional to work around an issue in the newer version, downgrading dependencies can reintroduce previously fixed bugs or security vulnerabilities.

Could you please provide some context for this change? If this downgrade is necessary, it would be good to add a comment in the docker-compose.yml file explaining the reason.

expose:
- "5100"

Expand Down
1 change: 0 additions & 1 deletion embedder_service/models/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ProcessingConfig(BaseModel):
default=512, description="Target chunk size in characters")
overlap: int = Field(
default=50, description="Overlap between chunks in characters")
# Default embedding model provided by Sentence Transformers
embedding_model: str = Field(
default=EMBEDDING_MODEL_NAME, description="Sentence Transformer model")
breakpoint_threshold_type: BreakpointThresholdType = Field(
Expand Down
3 changes: 0 additions & 3 deletions embedder_service/models/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ def embed_query(self, text: str) -> List[float]:
"""Embed a single query"""
embedding = self.model.encode([text], convert_to_tensor=False)
return embedding[0].tolist()

# def name(self) -> str:
# return "sentence_transformer"


@lru_cache(maxsize=5)
Expand Down
Binary file modified embedder_service/requirements.txt
Binary file not shown.
20 changes: 6 additions & 14 deletions embedder_service/routers/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async def data_chunking(request:DataRequest, chunker) -> List[Dict[str, Any]]:
# First iteration: Extract first chunk of doc.page_content
chunk_content = chunk.page_content
logger.info(f"Length of chunk {i+1}: {len(chunk_content.strip())}")
# First iteration: Start from first chunk of doc.page_context

chunk_start = request.text.find(chunk_content, current_pos)

if chunk_start == -1:
Expand Down Expand Up @@ -105,7 +105,7 @@ async def data_chunking(request:DataRequest, chunker) -> List[Dict[str, Any]]:
return chunk_data
except Exception as e:
logger.error(f"Semantic chunking failed: {e}")
raise HTTPException(status_code=500, detail=f"Processing failed: {str(e)}")
raise HTTPException(status_code=500, detail="Data chunking failed.")


async def vectorize_chromadb(chunk_data: List[Dict[str, Any]], config: ProcessingConfig, emb_model):
Expand All @@ -120,15 +120,7 @@ async def vectorize_chromadb(chunk_data: List[Dict[str, Any]], config: Processin
logger.info(f"Using existing collection: {config.collection_name}")
except Exception as e:
logger.error(f"Collection retrieval failed: {e}")
raise HTTPException(status_code=500, detail=f"Collection retrieval failed: {str(e)}")

# for chunk in chunk_data:
# collection.add(
# ids=[chunk['chunk_id']],
# documents=[chunk["content"]],
# metadatas=[chunk["metadata"]]
# )
# logger.info(f"Added chunk {chunk['chunk_id']} to collection")
raise HTTPException(status_code=500, detail="Collection retrieval failed.")

ids = [chunk['chunk_id'] for chunk in chunk_data]
documents = [chunk['content'] for chunk in chunk_data]
Expand Down Expand Up @@ -167,7 +159,7 @@ async def vectorize_chromadb(chunk_data: List[Dict[str, Any]], config: Processin

except Exception as e:
logger.error(f"Embedding process failed: {e}")
raise HTTPException(status_code=500, detail=f"Embedding failed: {str(e)}")
raise HTTPException(status_code=500, detail="Embedding failed")


# def serialize_chroma_results(results: Dict[str, Any]) -> Dict[str, Any]:
Expand Down Expand Up @@ -239,7 +231,7 @@ async def pdf_embedder_service(request: DataRequest):
}
except Exception as e:
logger.error(f"PDF embedder service failed: {e}")
raise HTTPException(status_code=500, detail=f"Service failed: {str(e)}")
raise HTTPException(status_code=500, detail="PDF embedder service failed")


@router.get("/status/{doc_id}")
Expand Down Expand Up @@ -277,4 +269,4 @@ async def verify_document_embedding(doc_id: str, collection_name: str = "my_docu

except Exception as e:
logger.error(f"Document verification failed: {e}")
raise HTTPException(status_code=500, detail=f"Verification failed: {str(e)}")
raise HTTPException(status_code=500, detail="Document verification failed")
5 changes: 5 additions & 0 deletions nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM nginx:1.29.0-alpine

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The Docker image nginx:1.29.0-alpine does not exist on Docker Hub, which will cause the docker-compose build command to fail. The latest mainline version of Nginx is 1.27.0 and the latest stable version is 1.26.1.

Please use a valid and existing image tag to ensure the build is successful.

FROM nginx:1.27.0-alpine


EXPOSE 8080

COPY ./nginx/nginx.conf.template /etc/nginx/templates/default.conf.template
3 changes: 3 additions & 0 deletions nginx/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PDF_PROCESSOR_URL=http://pdf_processor_service:8000
PDF_EXTRACTOR_URL=http://pdf_extraction_service:8000
CHAT_URL=http://chat_service:8000
22 changes: 22 additions & 0 deletions nginx/nginx.conf.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
server {
listen 8080;
server_name localhost;

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_set_header Host $host;

location /pdf_processor/ {
proxy_pass ${PDF_PROCESSOR_URL}/;
}

location /pdf_extraction/ {
proxy_pass ${PDF_EXTRACTOR_URL}/;
}

location /chat/ {
proxy_pass ${CHAT_URL}/;
}
}
2 changes: 1 addition & 1 deletion pdf_extraction_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)

app = FastAPI()
app = FastAPI(root_path="/pdf_extraction")

app.include_router(health.router)
app.include_router(extractor.router)
2 changes: 1 addition & 1 deletion pdf_processor_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s"
)

app = FastAPI()
app = FastAPI(root_path="/pdf_processor")

app.include_router(health.router)
app.include_router(document.router)
Expand Down