{
 "schema_version": 1,
 "generated": "2026-10-20",
 "id": "cdcailf-cjkfold--fold-rag-corpus-and-queries",
 "repo": "cdcailf/cjkfold",
 "repo_url": "https://github.com/cdcailf/cjkfold",
 "repo_slug": "cdcailf-cjkfold",
 "title": "Fold a RAG corpus and its queries so Chinese terms match",
 "page_title": "How to fold a RAG corpus and its queries so Chinese terms match with Cjkfold",
 "summary": "Apply folding on the way into the index and on the way out, then restore verbatim matches with rerank.",
 "who": "An engineer running a retrieval pipeline over Chinese PDFs whose vector search ranks unrelated short documents above the one that contains the query verbatim.",
 "problem": "Folding only the index or only the query silently disables matching, and dense retrieval handles literal tokens poorly.",
 "outcome": "A pipeline where the corpus and the query are folded the same way, and the verbatim matches are moved back to the top of the results.",
 "steps": [
  "`pip install cjkfold`",
  "`from cjkfold import fold, fold_documents, rerank`",
  "Wrap the loader output with `documents = fold_documents(loader.load())` before embedding.",
  "Fold the question with `hits = vectorstore.similarity_search_with_score(fold(question), k=20)`, then pass the results through `rerank(question, documents, scores)`.",
  "Re-embed the existing index, since text already stored is not repaired retroactively."
 ],
 "agent_prompt": "Using the cjkfold repo, add fold_documents to the document loading step of <path-to-pipeline-file> and fold the question before the vector search. Report which documents move up after rerank for the query <query-text>. Verify that the folded question and the folded stored text both contain the target term when checked with the in operator.",
 "agents": [
  "any"
 ],
 "difficulty": "Advanced",
 "time": "1 hour",
 "basis": "readme",
 "caveat": "Documents already in your vector store keep their look-alike characters until you rebuild the embeddings, so the fix only applies to text added or re-indexed after the change.",
 "category": "Software and DevOps",
 "tags": [
  "Software and DevOps"
 ],
 "lang": "python",
 "requirements": [
  "Python 3.9 or newer with pip",
  "Plain text extracted from the PDF, for example with pdftotext",
  "A terminal for the command line examples, or a Python project for the library calls"
 ],
 "risk": "none",
 "seen_in_the_wild": false,
 "mentioned_publicly": false,
 "risks": [],
 "best": false,
 "score": 0.9,
 "evidence": [],
 "url": "https://dedupedai.com/use-cases/cdcailf-cjkfold/fold-rag-corpus-and-queries/",
 "md": "https://dedupedai.com/use-cases/cdcailf-cjkfold/fold-rag-corpus-and-queries/index.md",
 "disclaimer": "Deduped lists open-source repositories that belong to other people. We do not own, maintain, audit, or vouch for any of them, and a repo appearing here is not an endorsement or a safety check. The use cases, steps, and prompts are written by AI and may be incomplete, outdated, or just wrong. Where a use case is marked \"Seen in the wild\", we link to public posts where someone described something similar, but we have not verified those posts and the use case itself is still our AI's own write-up. Use all of this at your own risk. Only run code, commands, or agents on systems and accounts you are authorized to use, and read the code and every command before you run it, especially anything that touches credentials, files, or the network. Nothing here is professional, security, legal, or financial advice. All trademarks and project names belong to their respective owners, and their use here does not imply affiliation. Content is provided as is, without warranties of any kind. Found a mistake, a safety problem, or something you want removed? Email hello@dedupedai.com and we will look at it promptly.",
 "api": "https://dedupedai.com/api/v1/usecases/cdcailf-cjkfold--fold-rag-corpus-and-queries.json",
 "api_version": "v1"
}
