Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
6 changes: 3 additions & 3 deletions docs-agent-mcp/mcp-server/embeddings_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import flo_tracing

DEFAULT_TIMEOUT_SEC = int(os.getenv("EMBEDDINGS_TIMEOUT_SEC", "60"))
# TEI all-mpnet-base-v2: each input must be <384 tokens.
MAX_TEI_INPUT_CHARS = int(os.getenv("MAX_TEI_INPUT_CHARS", "1000"))
# TEI BAAI/bge-base-en-v1.5: inputs up to 512 tokens (~2000 chars).
MAX_TEI_INPUT_CHARS = int(os.getenv("MAX_TEI_INPUT_CHARS", "2000"))


def embed_texts(
Expand All @@ -21,7 +21,7 @@ def embed_texts(
batch_size: int = 8,
timeout: int = DEFAULT_TIMEOUT_SEC,
) -> list[list[float]]:
"""Return embedding vectors for each input string (768-dim for all-mpnet-base-v2)."""
"""Return embedding vectors for each input string (768-dim for BAAI/bge-base-en-v1.5)."""
if not texts:
return []

Expand Down
2 changes: 1 addition & 1 deletion docs-agent-mcp/pipelines/code-pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def chunk_code_file(content, file_path, c_size, c_overlap):

print(f"Created {len(records)} code chunks; requesting embeddings from TEI service...")

max_tei_chars = 1000
max_tei_chars = 2000
for i in range(0, len(records), embedding_batch_size):
batch = records[i:i + embedding_batch_size]
texts = [r["content_text"][:max_tei_chars] for r in batch]
Expand Down
4 changes: 2 additions & 2 deletions docs-agent-mcp/pipelines/incremental-pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ def chunk_and_embed_incremental(

print(f"Created {len(records)} total chunks for incremental update; requesting embeddings from TEI service...")

# TEI all-mpnet-base-v2 rejects any input >=384 tokens (~1000 chars).
max_tei_chars = 1000
# TEI BAAI/bge-base-en-v1.5 accommodates up to 512 tokens (~2000 chars).
max_tei_chars = 2000
for i in range(0, len(records), embedding_batch_size):
batch = records[i:i + embedding_batch_size]
texts = [r["content_text"][:max_tei_chars] for r in batch]
Expand Down
2 changes: 1 addition & 1 deletion docs-agent-mcp/pipelines/issues-pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def content_segments(issue):

print(f"Total chunks: {len(records)}; requesting embeddings from TEI service...")

max_tei_chars = 1000
max_tei_chars = 2000
for i in range(0, len(records), embedding_batch_size):
batch = records[i:i + embedding_batch_size]
texts = [r["content_text"][:max_tei_chars] for r in batch]
Expand Down
16 changes: 8 additions & 8 deletions docs-agent-mcp/pipelines/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"http://embeddings-service-predictor.ml-infra.svc.cluster.local/embed"
)
DEFAULT_MILVUS_HOST = "milvus-milvus.ml-infra.svc.cluster.local"
# all-mpnet-base-v2 output size; other TEI models may differ — pass embedding_dim.
# BAAI/bge-base-en-v1.5 output size; other TEI models may differ — pass embedding_dim.
DEFAULT_EMBEDDING_DIM = 768
# Docs defaults: YAML-heavy pages tokenize denser than prose, so keep TEI inputs
# well under the 384-token ceiling (1000 chars produced HTTP 413 on Katib docs).
DEFAULT_DOCS_CHUNK_SIZE = 600
DEFAULT_DOCS_CHUNK_OVERLAP = 60
DEFAULT_DOCS_MAX_TEI_CHARS = 600
# Generic TEI ceiling used by non-docs pipelines / helpers.
MAX_TEI_INPUT_CHARS = 1000
# Docs defaults: BAAI/bge-base-en-v1.5 supports 512 tokens (~2000 chars), cleanly
# accommodating full canonical documentation and code chunks (MAX_CONTENT_TEXT_CHARS = 2000).
DEFAULT_DOCS_CHUNK_SIZE = 2000
DEFAULT_DOCS_CHUNK_OVERLAP = 200
DEFAULT_DOCS_MAX_TEI_CHARS = 2000
# Generic TEI ceiling used by non-docs pipelines / helpers (bge-base-en-v1.5 512-token ceiling).
MAX_TEI_INPUT_CHARS = 2000
# Batch count only; per-input size is limited by max_tei_chars / MAX_TEI_INPUT_CHARS.
DEFAULT_EMBEDDING_BATCH_SIZE = 8

Expand Down
4 changes: 2 additions & 2 deletions docs-agent-mcp/terraform/embeddings.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# =============================================================================
# embeddings.tf
# Deploys the sentence-transformers/all-mpnet-base-v2 model as a CPU-based
# Deploys the BAAI/bge-base-en-v1.5 model as a CPU-based
# KServe InferenceService using Hugging Face Text Embeddings Inference (TEI).
# =============================================================================

Expand All @@ -23,7 +23,7 @@ spec:
- ${var.embeddings_model_id}
- --port
- "8080"
# Truncate inputs to model max tokens instead of HTTP 413 (mpnet = 384 tokens).
# Truncate inputs to model max tokens instead of HTTP 413 (bge-base = 512 tokens).
- --auto-truncate
- --max-client-batch-size
- "${var.embeddings_max_client_batch_size}"
Expand Down
2 changes: 1 addition & 1 deletion docs-agent-mcp/terraform/terraform.tfvars.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
# ]

# --- TEI embeddings (ml-infra) ---
# embeddings_model_id = "sentence-transformers/all-mpnet-base-v2"
# embeddings_model_id = "BAAI/bge-base-en-v1.5"
# embeddings_max_client_batch_size = "64"
# embeddings_max_batch_tokens = "16384"
2 changes: 1 addition & 1 deletion docs-agent-mcp/terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ variable "milvus_version" {
variable "embeddings_model_id" {
description = "Hugging Face model ID served by TEI (must match pipeline/MCP embedding dimension)"
type = string
default = "sentence-transformers/all-mpnet-base-v2"
default = "BAAI/bge-base-en-v1.5"
}

variable "embeddings_max_client_batch_size" {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_pipeline_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def test_nested_html_tags(self):
class TestTruncateForTei:
def test_truncates_long_text(self):
long = "word " * 500
assert len(truncate_for_tei(long)) == 1000
assert len(truncate_for_tei(long)) == 2000


class TestEmbedTexts:
Expand Down Expand Up @@ -248,4 +248,4 @@ def fake_post(url, json, headers, timeout):
monkeypatch.setattr("utils.requests.post", fake_post)
long = "x" * 5000
embed_texts([long], "http://embeddings/embed", batch_size=1)
assert len(sent[0]) == 1000
assert len(sent[0]) == 2000