feat(ingestion): implement Phase 4 chunking and vector embedding generation
- Add heading and paragraph-preserving chunking algorithms with bounded overlap - Implement OpenAI embeddings client adapter with explicit token limits and batching - Implement stage_document pipeline with strict operational limits and memory protections - Add unit and integration tests covering chunking boundaries, timeouts, and vector generation
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
"""Deterministic provider for database acceptance; no network or tokenizer."""
|
||||
import hashlib
|
||||
|
||||
from app.modules.documents.embeddings import EmbeddingProviderError
|
||||
|
||||
|
||||
class DeterministicEmbeddings:
|
||||
def __init__(self, settings, *, observe=None, fail_at=None):
|
||||
self.profile = settings.embedding_profile
|
||||
self.request_policy = settings.processing_profile()["embedding_request"]
|
||||
self.calls = []
|
||||
self.observe, self.fail_at = observe, fail_at
|
||||
|
||||
@staticmethod
|
||||
def vector(value):
|
||||
digest = hashlib.sha256(value.encode("utf-8")).digest()
|
||||
return [float(1 + digest[i]) for i in range(3)]
|
||||
|
||||
def embed(self, texts):
|
||||
self.calls.append(tuple(texts))
|
||||
if self.observe:
|
||||
self.observe(len(self.calls))
|
||||
if len(self.calls) == self.fail_at:
|
||||
raise EmbeddingProviderError("injected secret provider payload", retryable=False)
|
||||
return [self.vector(value) for value in texts]
|
||||
Reference in New Issue
Block a user