A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.
Shell
Make document chunks match the RAG ingestion contract
Rudy Celekli0e1374a84e0b
diff --git a/engineering/engineering-rag-pipeline-engineer.md b/engineering/engineering-rag-pipeline-engineer.mdindex ff5b854c..5b85882b 100644--- a/engineering/engineering-rag-pipeline-engineer.md+++ b/engineering/engineering-rag-pipeline-engineer.md@@ -70,7 +70,7 @@ You've built these systems for real workloads: multilingual corpora, domain-spec### Chunking Strategy — Semantic + Structural```python-from langchain.text_splitter import MarkdownHeaderTextSplitter, RecursiveCharacterTextSplitter+from langchain_text_splitters import MarkdownHeaderTextSplitter, RecursiveCharacterTextSplitterdef chunk_document(text: str, doc_type: str) -> list[dict]:"""@@ -96,7 +96,7 @@ def chunk_document(text: str, doc_type: str) -> list[dict]:for doc in header_chunks:sub_chunks = char_splitter.split_documents([doc])chunks.extend(sub_chunks)- return chunks+ return [{"content": doc.page_content, "metadata": doc.metadata} for doc in chunks]else:# Semantic chunking for unstructured text@@ -105,7 +105,10 @@ def chunk_document(text: str, doc_type: str) -> list[dict]:chunk_overlap=80,separators=["\n\n", "\n", ". ", "! ", "? ", " "])- return splitter.create_documents([text])+ return [+ {"content": doc.page_content, "metadata": doc.metadata}+ for doc in splitter.create_documents([text])+ ]```### pgvector Schema & HNSW Index@@ -141,6 +144,7 @@ CREATE INDEX ON document_chunks (document_id);```pythonimport asyncio+import jsonfrom openai import AsyncOpenAIfrom pgvector.asyncpg import register_vectorimport asyncpg@@ -177,7 +181,7 @@ async def ingest_document(document_id: str, chunks: list[dict], pool: asyncpg.PoVALUES ($1, $2, $3, $4, $5)""",[- (document_id, c["content"], emb, idx, c.get("metadata", {}))+ (document_id, c["content"], emb, idx, json.dumps(c.get("metadata", {})))for idx, (c, emb) in enumerate(zip(chunks, embeddings))])