🔧 ProgrammierungBolt.new launches Forge to widen who gets to build with AI(17.09.2026 um 22:12 Uhr)
🔧 ProgrammierungGlobal Workspace Theory The J-Space of Claude(17.09.2026 um 22:12 Uhr)
🔧 AI Nachrichten I let a local 27B LLM audit and fix my Splunk + Sysmon stack(17.09.2026 um 22:15 Uhr)
🔧 ProgrammierungHow to Run Docker/Containers With Termux(17.09.2026 um 22:20 Uhr)
🔧 ProgrammierungI Accidentally Built a Dark Software Factory. Here's How.(17.09.2026 um 22:21 Uhr)
🔧 ProgrammierungCongrats to the DEV Weekend Challenge: Dog Days Edition Winners!(17.09.2026 um 22:22 Uhr)
🔧 ProgrammierungBolt.new launches Forge to widen who gets to build with AI(17.09.2026 um 22:12 Uhr)
🔧 ProgrammierungGlobal Workspace Theory The J-Space of Claude(17.09.2026 um 22:12 Uhr)
🔧 AI Nachrichten I let a local 27B LLM audit and fix my Splunk + Sysmon stack(17.09.2026 um 22:15 Uhr)
🔧 ProgrammierungHow to Run Docker/Containers With Termux(17.09.2026 um 22:20 Uhr)
🔧 ProgrammierungI Accidentally Built a Dark Software Factory. Here's How.(17.09.2026 um 22:21 Uhr)
🔧 ProgrammierungCongrats to the DEV Weekend Challenge: Dog Days Edition Winners!(17.09.2026 um 22:22 Uhr)
🔧 Programmierung 🕛 vor 2 Monaten 5 Min Lesezeit
0

Candidate Compliance Agent: Building a Multilingual RAG System for Tamil Nadu Election Affidavits

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




The Problem Nobody Talks About



Every election cycle in India, candidates are not easily accessible to many so they don't the many information about candidate's they are voting for.






What I Built



Candidate Compliance Agent is an AI agent that lets anyone query Tamil Nadu election candidate affidavits in plain English or Tamil. Ask it about assets, criminal records, income declarations, education — it answers from the actual documents.



Live demo: https://affidavit-rag-frontend.vercel.app






The Technical Challenge



This wasn't a clean dataset project. The raw materials were:



Scanned PDFs (~6MB each)

Mixed Tamil and English text

Stamp paper backgrounds with notary seals overlaid on text

Inconsistent formatting across candidates





Architecture Overview



React Frontend (Vercel)



Flask Backend (Railway)



Hindsight Memory (recall past context)



Intent Router



Structured Query OR Semantic RAG



Groq LLM (Llama 3.3 70B)



Hindsight Memory (retain new context)



Response + Follow-up Questions



Technical Feature Implemnentaion Walkthrough





OCR Pipeline



The first challenge was extracting text from scanned PDFs. I used Tesseract with Tamil + English language models:




CODE
python

text = pytesseract.image_to_string(
image,
lang="eng+tam",
config="--psm 6"
)






--psm 6 treats each page as a uniform text block — critical for structured affidavit forms.



Each PDF was converted to images at 300 DPI using pdf2image, then OCR'd page by page. Output was stored as JSON with metadata:




CODE
{
"text": "...",
"metadata": {
"candidate": "MKStalin",
"party": "DMK",
"constituency": "KOLATHUR",
"page": 3
}
}










Semantic Document Building



The biggest architectural decision was how to chunk the data.

Naive approach: Split each page into 500-token chunks with overlap. This gives you 600+ noisy chunks where assets, criminal records, and education are all mixed together.

Better approach: Build one semantic document per topic per candidate.

Each candidate gets 6 documents:



Identity and contact

Education

Criminal cases (structured)

Criminal detail (raw OCR text)

Income tax

Assets and liabilities




CODE
def build_docs(candidate, raw_pages):
docs = []
docs.append({"section": "criminal_cases", "text": f"""
Candidate:
{name}
Party:
{party}
Section: Criminal Cases

Pending Cases:
{pending}
Convicted Cases:
{convicted}
Summary:
{"No criminal record" if pending == 0 else f"{pending} pending"}
"""})
# ... repeat for each section
return docs







35 candidates × 6 sections = 210 clean semantic documents instead of 600+ noisy chunks.

Result: When someone asks "does certain candidate have criminal cases?" the retrieval hits the criminal_cases document directly instead of a random page slice.





Embeddings and Vector Store



I used paraphrase-multilingual-MiniLM-L12-v2 for embeddings — a sentence transformer model that handles Tamil and English in the same vector space.



model = SentenceTransformer("paraphrase-multilingual-MiniLM-L12-v2")

embeddings = model.encode(texts, batch_size=32).tolist()




CODE
collection.add(
documents=texts,
embeddings=embeddings,
metadatas=[{
"candidate": d["candidate"],
"party": d["party"],
"section": d["section"],
} for d in all_docs],
ids=[f"{d['candidate']}_{d['section']}" for d in all_docs]
)









Intent Router



there are 5 intent category based on that the query is passed through




CODE
def detect_intent(query):
q = query.lower()
for party in PARTIES:
if party in q:
return "party"
for pattern in EDUCATION_PATTERNS:
if re.search(pattern, q):
return "education"
for word in SEMANTIC_KEYWORDS:
if word in q:
return "semantic"
return "unknown"









Hindsight Memory Integration



Hindsight is a persistent memory service that stores and recalls context across sessions. When a user comes back the next day and asks a follow-up question, the agent remembers what they asked before.




CODE
from hindsight_client import Hindsight

client = Hindsight(
base_url="https://api.hindsight.vectorize.io",
api_key=os.getenv("HINDSIGHT_API_KEY")
)

def recall_memory(session_id, query):
result = client.recall(
bank_id="candidate-rag",
query=f"Session: {session_id}\nQuestion: {query}"
)
return "\n".join([m.text for m in result.results])

def retain_memory(session_id, memory):
client.retain(
bank_id="candidate-rag",
content=memory,
metadata={"session_id": session_id}
)









USING THE MEMORY STORED IN HINDSIGHT






1. Recall past context



past_memory = recall_memory(session_id, query)






2. Inject into RAG prompt



prompt = f"""

Previous context: {past_memory}



Context from affidavits: {retrieved_context}



Question: {query}

"""






3. Get answer



answer = ask_groq(prompt)






4. Store this exchange



retain_memory(session_id, f"User asked: {query}. Answer: {answer[:200]}")



Why this matters: A voter researching a candidate can ask multiple questions across multiple sessions and get progressively better, context-aware answers.






Contextual Follow-up Questions



After every answer, the LLM generates 4 follow-up questions based on the query, retrieved context, and memory:



ANSWER:

Poornima has no pending criminal cases.



FOLLOW_UP_QUESTIONS:




  1. What are Poornima's total declared assets?

  2. What is Poornima's declared annual income?

  3. What is Poornima's educational qualification?



These appear as clickable buttons — clicking fills the input box directly.






Deployment



Backend: Flask + gunicorn on Railway

Frontend: React on Vercel

Vector DB: ChromaDB (persistent, committed to GitHub)

LLM: Groq API (Llama 3.3 70B Versatile)

Memory: Hindsight






What I Learned




  1. OCR quality determines everything downstream. Bad OCR produces bad embeddings. The --psm 6 config change improved Tamil extraction significantly.


  2. Semantic chunking beats token chunking. 210 topic-focused documents retrieve better than 600+ random page slices.


  3. Persistent memory changes the interaction model. Without Hindsight, every conversation starts cold. With it, the agent builds understanding over time.


  4. Real-world data is always messier than tutorials suggest. Stamp paper backgrounds, notary seal overlays, mixed scripts — none of this appears in RAG tutorials.




What's Next



Scale to all 234 Tamil Nadu constituencies (~4500 PDFs)

Add proactive alerts when new affidavits are filed

Support voice queries in Tamil

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Bolt.new launches Forge to widen who gets to build with AI
1 Quelle
Common Pitfalls in RAG Applications: What to Avoid When Using Vector Search and Embeddings
1 Quelle
Turn Your Android Phone Into a Local Development Server With Termux
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Candidate Compliance Agent: Building a Multilingual RAG System for Tamil Nadu Election Affidavits

Thematisch verwandte Begriffe: Candidate, Compliance, Agent, Building · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...