Spaces:
Sleeping

p4r5kpftnp-cmd Claude Sonnet 4.6 commited on
Commit
3ac681e
·
1 Parent(s): 4562b5e

Add LangChain/LangGraph RAG pipeline for retrieval-augmented proof generation

Browse files

- src/mathlib_corpus.py: walks Mathlib4 .lean source files and extracts
theorem/lemma/def declarations as LangChain Documents
- src/retriever.py: MathLibRetriever — FAISS + BM25 hybrid retrieval via
EnsembleRetriever (60/40), reranked with CrossEncoder; index persisted to
data/mathlib_index/ for reuse across runs
- src/rag_chain.py: RAGProofChain — LangChain LCEL chain
(ChatPromptTemplate | OllamaLLM | StrOutputParser) that injects retrieved
lemma context into each proof-generation call
- src/langgraph_agent.py: LangGraphAgent — replaces the plain Python retry
loop with a proper state machine (verify → retrieve → generate → verify);
exposes the same solve_file() API
- src/proof_agent.py: thin backward-compatible wrapper around LangGraphAgent
- scripts/build_index.py: one-time offline script to build and save the FAISS
index from Mathlib4 source
- scripts/run_agent.py: updated to use LangGraphAgent directly
- requirements.txt: add faiss-cpu, rank-bm25, sentence-transformers,
langgraph, langchain-ollama

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

13 files changed +772
Files changed (13)
problems/simple_add.leanAdded+4
problems/test_problem.leanAdded+4
requirements.txtAdded+9
scripts/build_index.pyAdded+40
scripts/run_agent.pyAdded+36
src/langgraph_agent.pyAdded+173
src/lean_verifier.pyAdded+70
src/lmm_client.pyAdded+54
src/mathlib_corpus.pyAdded+117
src/proof_agent.pyAdded+11
src/rag_chain.pyAdded+71
src/retriever.pyAdded+126
tests/test_lean_verifier.pyAdded+57