Use this file to discover all available pages before exploring further.
GraphRAG enables powerful question-answering (Q&A) systems that go beyond simple keyword matching to provide context-aware, accurate answers grounded in your documents.
input: type: text # or csv, json file_pattern: .*\.txt$chunking: size: 400 # Smaller chunks for precise retrieval overlap: 100 # Good overlap for contextentity_extraction: # Use auto-tuning for domain-specific entities enabled: true
Run indexing:
graphrag index --root ./qa_system
3
Query your documents
Ask questions in natural language:
# Specific factual questionsgraphrag query "What is the vacation policy for employees?" --method local# Broad overview questionsgraphrag query "What are the main safety requirements?" --method global# Relationship questionsgraphrag query "How does the benefits package relate to employee tenure?" --method local
# Multi-hop reasoningresult = await drift_search.search( "How do safety training requirements vary based on job role and department?")# Causal questionsresult = await drift_search.search( "What factors contribute to eligibility for the executive bonus program?")# Exploratory questionsresult = await drift_search.search( "What are all the ways an employee can request schedule changes?")
from graphrag.query.question_gen.local_gen import LocalQuestionGenquestion_generator = LocalQuestionGen( model=chat_model, context_builder=context_builder, tokenizer=tokenizer,)# After answering a questionquestion_history = ["What are the vacation policies?"]suggestions = await question_generator.agenerate( question_history=question_history, context_data=None, question_count=5)print("Suggested follow-up questions:")for q in suggestions.response: print(f"- {q}")# Output:# - How do employees request vacation time?# - What is the vacation accrual rate?# - Are there blackout dates for vacation?# - How does vacation time carry over between years?# - What happens to unused vacation when an employee leaves?
# Legal document Q&A setupentity_types = [ "CASE", "STATUTE", "PARTY", "COURT", "LEGAL_CONCEPT", "DATE", "JURISDICTION"]# Example queriesqueries = [ "What are the key precedents for contract disputes?", "Who are the parties involved in Case ABC-123?", "What statutory requirements apply to this situation?",]
# Technical docs Q&A setupentity_types = [ "API", "FUNCTION", "CLASS", "MODULE", "PARAMETER", "ERROR", "CONFIGURATION"]# Example queriesqueries = [ "How do I authenticate API requests?", "What parameters does the login function accept?", "What are the common error codes and their meanings?",]
# Medical Q&A setup (ensure HIPAA compliance!)entity_types = [ "PATIENT", "CONDITION", "MEDICATION", "PROCEDURE", "PROVIDER", "FACILITY"]# Example queriesqueries = [ "What medications is the patient currently taking?", "What procedures were performed during the visit?", "What are the patient's known allergies?",]
# Support docs Q&A setupentity_types = [ "PRODUCT", "FEATURE", "ISSUE", "SOLUTION", "REQUIREMENT", "VERSION"]# Example queriesqueries = [ "How do I reset my password?", "What are the system requirements for version 2.0?", "How do I troubleshoot connection issues?",]
# Create question-answer pairs for evaluationtest_set = [ { "question": "What is the vacation policy?", "expected_answer_contains": ["15 days", "accrual", "calendar year"], "method": "local" }, { "question": "What are the main employee benefits?", "expected_answer_contains": ["health insurance", "401k", "vacation"], "method": "global" },]# Run evaluationfor test in test_set: result = await search_engine.search(test["question"]) # Check if expected content is present score = sum( 1 for term in test["expected_answer_contains"] if term.lower() in result.response.lower() ) / len(test["expected_answer_contains"]) print(f"Q: {test['question']}") print(f"Score: {score:.0%}") print(f"A: {result.response[:200]}...\n")