from __future__ import annotations from app.modules.rag.contracts import RagDocument, RagLayer, RagSource, RagSpan from app.modules.rag.indexing.code.symbols.extractor import PySymbol class SymbolDocumentBuilder: def build(self, source: RagSource, symbol: PySymbol) -> RagDocument: body = [f"{symbol.kind} {symbol.qname}", symbol.signature] if symbol.docstring: body.append(symbol.docstring.strip()) return RagDocument( layer=RagLayer.CODE_SYMBOL_CATALOG, lang="python", source=source, title=symbol.qname, text="\n".join(part for part in body if part), span=RagSpan(symbol.start_line, symbol.end_line), metadata={ "symbol_id": symbol.symbol_id, "qname": symbol.qname, "kind": symbol.kind, "signature": symbol.signature, "decorators_or_annotations": symbol.decorators, "docstring_or_javadoc": symbol.docstring, "parent_symbol_id": symbol.parent_symbol_id, "package_or_module": source.path.replace("/", ".").removesuffix(".py"), "is_entry_candidate": bool(symbol.decorators), "lang_payload": symbol.lang_payload, "artifact_type": "CODE", }, )