Instructions to use Navaneeth-14/rag-hackathon-app with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Navaneeth-14/rag-hackathon-app with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf Navaneeth-14/rag-hackathon-app:Q4_K_M # Run inference directly in the terminal: llama cli -hf Navaneeth-14/rag-hackathon-app:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Navaneeth-14/rag-hackathon-app:Q4_K_M # Run inference directly in the terminal: llama cli -hf Navaneeth-14/rag-hackathon-app:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf Navaneeth-14/rag-hackathon-app:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf Navaneeth-14/rag-hackathon-app:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf Navaneeth-14/rag-hackathon-app:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf Navaneeth-14/rag-hackathon-app:Q4_K_M
Use Docker
docker model run hf.co/Navaneeth-14/rag-hackathon-app:Q4_K_M
- LM Studio
- Jan
- Ollama
How to use Navaneeth-14/rag-hackathon-app with Ollama:
ollama run hf.co/Navaneeth-14/rag-hackathon-app:Q4_K_M
- Unsloth Studio
How to use Navaneeth-14/rag-hackathon-app with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Navaneeth-14/rag-hackathon-app to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for Navaneeth-14/rag-hackathon-app to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for Navaneeth-14/rag-hackathon-app to start chatting
- Docker Model Runner
How to use Navaneeth-14/rag-hackathon-app with Docker Model Runner:
docker model run hf.co/Navaneeth-14/rag-hackathon-app:Q4_K_M
- Lemonade
How to use Navaneeth-14/rag-hackathon-app with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Navaneeth-14/rag-hackathon-app:Q4_K_M
Run and chat with the model
lemonade run user.rag-hackathon-app-Q4_K_M
List all available models
lemonade list
- Atomic Chat
File size: 23,667 Bytes
09281fe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 | """
Advanced Query Parser for Natural Language Processing
Handles vague, incomplete, and plain English queries with entity extraction
"""
import re
import logging
from typing import List, Dict, Any, Optional, Tuple
from dataclasses import dataclass
from datetime import datetime
import json
# NLP and ML libraries
# import spacy # Temporarily commented out due to installation issues
# from transformers import pipeline # Temporarily commented out due to installation issues
import nltk
from nltk.tokenize import word_tokenize, sent_tokenize
from nltk.corpus import stopwords
from nltk.stem import WordNetLemmatizer
import numpy as np
# Optional imports with error handling
try:
from transformers import pipeline
TRANSFORMERS_AVAILABLE = True
except ImportError:
TRANSFORMERS_AVAILABLE = False
print("⚠️ Transformers not available. NER functionality will be limited.")
# Download required NLTK data
try:
nltk.data.find('tokenizers/punkt')
except LookupError:
nltk.download('punkt')
try:
nltk.data.find('corpora/stopwords')
except LookupError:
nltk.download('stopwords')
try:
nltk.data.find('corpora/wordnet')
except LookupError:
nltk.download('wordnet')
# Additional NLTK data that might be needed
try:
nltk.data.find('tokenizers/punkt_tab')
except LookupError:
try:
nltk.download('punkt_tab')
except:
pass # Ignore if punkt_tab is not available
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
@dataclass
class ParsedQuery:
"""Represents a parsed query with extracted information"""
original_query: str
enhanced_query: str
query_type: str # claim, coverage, policy, general, etc.
entities: Dict[str, List[str]]
intent: str
confidence: float
keywords: List[str]
synonyms: List[str]
context: Dict[str, Any]
timestamp: datetime
@dataclass
class QueryEntity:
"""Represents an extracted entity from a query"""
text: str
entity_type: str
confidence: float
start_pos: int
end_pos: int
class AdvancedQueryParser:
"""Advanced query parser with entity extraction and query enhancement"""
def __init__(self,
spacy_model: str = "en_core_web_sm",
use_gpu: bool = True):
self.use_gpu = use_gpu
self.spacy_model = spacy_model
# Initialize NLP components
self._initialize_nlp_components()
# Initialize entity extractors
self._initialize_entity_extractors()
# Initialize query enhancement
self._initialize_query_enhancement()
logger.info("Advanced Query Parser initialized")
def _initialize_nlp_components(self):
"""Initialize NLP components"""
try:
# Load spaCy model
# self.nlp = spacy.load(self.spacy_model) # Temporarily commented out due to installation issues
self.nlp = None # Set to None temporarily
# Initialize NLTK components
self.lemmatizer = WordNetLemmatizer()
self.stop_words = set(stopwords.words('english'))
# Add custom stop words for insurance domain
insurance_stop_words = {
'policy', 'claim', 'coverage', 'insurance', 'document',
'please', 'help', 'need', 'want', 'know', 'tell'
}
self.stop_words.update(insurance_stop_words)
logger.info("NLP components initialized")
except Exception as e:
logger.error(f"Error initializing NLP components: {e}")
raise
def _initialize_entity_extractors(self):
"""Initialize entity extraction components"""
try:
# Initialize NER pipeline if transformers is available
if TRANSFORMERS_AVAILABLE:
try:
device = 0 if self.use_gpu else -1
self.ner_pipeline = pipeline(
"ner",
model="dbmdz/bert-large-cased-finetuned-conll03-english",
device=device
)
logger.info("NER pipeline initialized")
except Exception as e:
logger.warning(f"NER pipeline initialization failed: {e}")
self.ner_pipeline = None
else:
self.ner_pipeline = None
logger.info("NER pipeline not available (transformers not installed)")
# Insurance-specific entity patterns (always available)
self.insurance_entities = {
'medical_condition': [
r'\b(heart attack|stroke|cancer|diabetes|hypertension|asthma|arthritis)\b',
r'\b(surgery|operation|procedure|treatment|therapy)\b',
r'\b(medication|prescription|drug|medicine)\b'
],
'coverage_type': [
r'\b(health|medical|dental|vision|life|auto|home|property)\s+(insurance|coverage|policy)\b',
r'\b(accident|disability|liability|comprehensive|collision)\b'
],
'amount': [
r'\$\d+(?:,\d{3})*(?:\.\d{2})?',
r'\b\d+\s*(?:dollars?|rupees?|euros?)\b',
r'\b(?:maximum|minimum|total|sum)\s+(?:of\s+)?\$\d+\b'
],
'time_period': [
r'\b(waiting period|grace period|coverage period|policy term)\b',
r'\b(\d+\s+(?:days?|weeks?|months?|years?))\b',
r'\b(immediate|urgent|emergency|routine)\b'
],
'document_type': [
r'\b(claim form|medical certificate|prescription|bill|receipt|invoice)\b',
r'\b(doctor|physician|specialist|hospital|clinic)\s+(?:report|note|letter)\b'
]
}
logger.info("Entity extractors initialized")
except Exception as e:
logger.error(f"Error initializing entity extractors: {e}")
# Set defaults if initialization fails
self.ner_pipeline = None
self.insurance_entities = {}
def _initialize_query_enhancement(self):
"""Initialize query enhancement components"""
try:
# Query enhancement patterns
self.enhancement_patterns = {
'claim_related': {
'keywords': ['claim', 'file', 'submit', 'process', 'approve', 'reject'],
'synonyms': ['application', 'request', 'petition', 'appeal'],
'context': 'claim_processing'
},
'coverage_related': {
'keywords': ['cover', 'include', 'exclude', 'limit', 'maximum', 'minimum'],
'synonyms': ['protection', 'benefit', 'entitlement', 'eligibility'],
'context': 'coverage_analysis'
},
'policy_related': {
'keywords': ['policy', 'terms', 'conditions', 'clause', 'section'],
'synonyms': ['agreement', 'contract', 'document', 'provision'],
'context': 'policy_review'
},
'medical_related': {
'keywords': ['medical', 'health', 'treatment', 'surgery', 'medication'],
'synonyms': ['healthcare', 'therapeutic', 'clinical', 'pharmaceutical'],
'context': 'medical_coverage'
}
}
# Query type classification patterns
self.query_types = {
'claim_inquiry': [
r'\b(how|what|can|is|does)\s+(?:to\s+)?(?:file|submit|process|claim)\b',
r'\b(claim|file|submit|process)\s+(?:a\s+)?(?:claim|request)\b'
],
'coverage_check': [
r'\b(cover|include|exclude|limit|maximum|minimum)\b',
r'\b(is|does|can)\s+(?:.*?)\s+(?:cover|include|exclude)\b',
r'\b(waiting\s+period|grace\s+period|coverage\s+period)\b',
r'\b(what\'s|what\s+is)\s+(?:the\s+)?(?:waiting|grace|coverage)\b'
],
'policy_review': [
r'\b(policy|terms|conditions|clause|section)\b',
r'\b(what|which|where)\s+(?:in\s+)?(?:policy|document)\b'
],
'medical_coverage': [
r'\b(medical|health|treatment|surgery|medication|prescription)\b',
r'\b(doctor|hospital|clinic|physician|specialist)\b',
r'\b(dental|dental\s+procedures|dental\s+treatment)\b',
r'\b(heart\s+surgery|cardiac|surgical)\b'
],
'general_inquiry': [
r'\b(what|how|when|where|why|who)\b',
r'\b(explain|describe|tell|show)\b'
]
}
logger.info("Query enhancement components initialized")
except Exception as e:
logger.error(f"Error initializing query enhancement: {e}")
def parse_query(self, query: str) -> ParsedQuery:
"""Main method to parse and enhance a query"""
try:
# Clean and preprocess query
cleaned_query = self._preprocess_query(query)
# Extract entities
entities = self._extract_entities(cleaned_query)
# Determine query type and intent
query_type, intent, confidence = self._classify_query(cleaned_query)
# Extract keywords
keywords = self._extract_keywords(cleaned_query)
# Generate synonyms
synonyms = self._generate_synonyms(keywords)
# Enhance query
enhanced_query = self._enhance_query(cleaned_query, entities, query_type)
# Build context
context = self._build_context(cleaned_query, entities, query_type)
parsed_query = ParsedQuery(
original_query=query,
enhanced_query=enhanced_query,
query_type=query_type,
entities=entities,
intent=intent,
confidence=confidence,
keywords=keywords,
synonyms=synonyms,
context=context,
timestamp=datetime.now()
)
logger.info(f"Query parsed successfully: {query_type} ({confidence:.2f})")
return parsed_query
except Exception as e:
logger.error(f"Error parsing query: {e}")
# Return a basic parsed query
return self._create_basic_parsed_query(query)
def _preprocess_query(self, query: str) -> str:
"""Preprocess and clean the query"""
try:
# Convert to lowercase
query = query.lower().strip()
# Remove extra whitespace
query = re.sub(r'\s+', ' ', query)
# Remove special characters but keep important ones
query = re.sub(r'[^\w\s\-\.\,\?\&]', '', query)
# Fix common abbreviations
query = self._fix_abbreviations(query)
return query
except Exception as e:
logger.error(f"Error preprocessing query: {e}")
return query
def _fix_abbreviations(self, query: str) -> str:
"""Fix common abbreviations in insurance queries"""
abbreviations = {
'dr.': 'doctor',
'doc.': 'document',
'med.': 'medical',
'rx': 'prescription',
'hosp.': 'hospital',
'clinic.': 'clinic',
'ins.': 'insurance',
'pol.': 'policy',
'claim.': 'claim',
'coverage.': 'coverage'
}
for abbr, full in abbreviations.items():
query = query.replace(abbr, full)
return query
def _extract_entities(self, query: str) -> Dict[str, List[str]]:
"""Extract entities from the query"""
entities = {}
try:
# Use spaCy for basic NER
# doc = self.nlp(query) # Temporarily commented out due to installation issues
# Extract named entities
# for ent in doc.ents: # Temporarily commented out due to installation issues
# entity_type = ent.label_.lower() # Temporarily commented out due to installation issues
# if entity_type not in entities: # Temporarily commented out due to installation issues
# entities[entity_type] = [] # Temporarily commented out due to installation issues
# entities[entity_type].append(ent.text) # Temporarily commented out due to installation issues
# Extract insurance-specific entities using patterns
for entity_type, patterns in self.insurance_entities.items():
entities[entity_type] = []
for pattern in patterns:
matches = re.findall(pattern, query, re.IGNORECASE)
entities[entity_type].extend(matches)
# Use BERT NER if available
if hasattr(self, 'ner_pipeline') and self.ner_pipeline is not None:
try:
ner_results = self.ner_pipeline(query)
for result in ner_results:
entity_type = result['entity'].lower()
if entity_type not in entities:
entities[entity_type] = []
entities[entity_type].append(result['word'])
except Exception as e:
logger.debug(f"BERT NER failed: {e}")
# Remove duplicates
for entity_type in entities:
entities[entity_type] = list(set(entities[entity_type]))
return entities
except Exception as e:
logger.error(f"Error extracting entities: {e}")
return {}
def _classify_query(self, query: str) -> Tuple[str, str, float]:
"""Classify the query type and determine intent"""
try:
best_type = 'general_inquiry'
best_confidence = 0.0
intent = 'information_seeking'
# Check each query type
for query_type, patterns in self.query_types.items():
confidence = 0.0
matches = 0
for pattern in patterns:
if re.search(pattern, query, re.IGNORECASE):
matches += 1
if matches > 0:
confidence = matches / len(patterns)
if confidence > best_confidence:
best_confidence = confidence
best_type = query_type
# Determine intent based on query type
intent_mapping = {
'claim_inquiry': 'claim_processing',
'coverage_check': 'coverage_analysis',
'policy_review': 'policy_review',
'medical_coverage': 'medical_coverage',
'general_inquiry': 'information_seeking'
}
intent = intent_mapping.get(best_type, 'information_seeking')
return best_type, intent, best_confidence
except Exception as e:
logger.error(f"Error classifying query: {e}")
return 'general_inquiry', 'information_seeking', 0.0
def _extract_keywords(self, query: str) -> List[str]:
"""Extract important keywords from the query"""
try:
# Tokenize with fallback
try:
tokens = word_tokenize(query)
except Exception as tokenize_error:
logger.warning(f"Word tokenization failed, using simple split: {tokenize_error}")
tokens = query.split()
# Remove stop words and lemmatize
keywords = []
for token in tokens:
if token.lower() not in self.stop_words and len(token) > 2:
try:
lemmatized = self.lemmatizer.lemmatize(token.lower())
keywords.append(lemmatized)
except Exception as lemmatize_error:
logger.debug(f"Lemmatization failed for '{token}': {lemmatize_error}")
keywords.append(token.lower())
return keywords
except Exception as e:
logger.error(f"Error extracting keywords: {e}")
return []
def _generate_synonyms(self, keywords: List[str]) -> List[str]:
"""Generate synonyms for keywords"""
synonyms = []
try:
# Simple synonym mapping for insurance domain
synonym_mapping = {
'claim': ['application', 'request', 'petition'],
'cover': ['include', 'protect', 'insure'],
'policy': ['document', 'agreement', 'contract'],
'medical': ['health', 'clinical', 'therapeutic'],
'surgery': ['operation', 'procedure', 'treatment'],
'hospital': ['clinic', 'medical center', 'facility'],
'doctor': ['physician', 'specialist', 'medical practitioner'],
'medicine': ['medication', 'drug', 'prescription'],
'cost': ['expense', 'charge', 'fee', 'amount'],
'limit': ['maximum', 'cap', 'ceiling', 'restriction']
}
for keyword in keywords:
if keyword in synonym_mapping:
synonyms.extend(synonym_mapping[keyword])
return list(set(synonyms))
except Exception as e:
logger.error(f"Error generating synonyms: {e}")
return []
def _enhance_query(self, query: str, entities: Dict[str, List[str]], query_type: str) -> str:
"""Enhance the query with additional context and synonyms"""
try:
enhanced_parts = [query]
# Add entity context
for entity_type, entity_list in entities.items():
if entity_list:
enhanced_parts.append(f"related to {entity_type}: {', '.join(entity_list)}")
# Add query type context
if query_type in self.enhancement_patterns:
pattern = self.enhancement_patterns[query_type]
enhanced_parts.append(f"context: {pattern['context']}")
# Add synonyms for important terms
synonyms = self._generate_synonyms(self._extract_keywords(query))
if synonyms:
enhanced_parts.append(f"synonyms: {', '.join(synonyms[:5])}")
return " | ".join(enhanced_parts)
except Exception as e:
logger.error(f"Error enhancing query: {e}")
return query
def _build_context(self, query: str, entities: Dict[str, List[str]], query_type: str) -> Dict[str, Any]:
"""Build context information for the query"""
try:
context = {
'query_length': len(query),
'has_entities': len(entities) > 0,
'entity_types': list(entities.keys()),
'query_type': query_type,
'is_medical': any('medical' in entity_type for entity_type in entities.keys()),
'has_amounts': 'amount' in entities,
'has_time_periods': 'time_period' in entities
}
return context
except Exception as e:
logger.error(f"Error building context: {e}")
return {}
def _create_basic_parsed_query(self, query: str) -> ParsedQuery:
"""Create a basic parsed query when parsing fails"""
return ParsedQuery(
original_query=query,
enhanced_query=query,
query_type='general_inquiry',
entities={},
intent='information_seeking',
confidence=0.0,
keywords=[],
synonyms=[],
context={},
timestamp=datetime.now()
)
def get_query_suggestions(self, query: str) -> List[str]:
"""Generate query suggestions based on the input"""
try:
suggestions = []
# Basic suggestions based on query type
if 'claim' in query.lower():
suggestions.extend([
"How do I file a claim?",
"What documents are needed for claim submission?",
"What is the claim processing time?",
"Can I track my claim status?"
])
if 'cover' in query.lower() or 'coverage' in query.lower():
suggestions.extend([
"What is covered under this policy?",
"What are the coverage limits?",
"Are pre-existing conditions covered?",
"What is not covered?"
])
if 'medical' in query.lower() or 'health' in query.lower():
suggestions.extend([
"What medical procedures are covered?",
"Are prescription drugs covered?",
"What is the coverage for hospital stays?",
"Are specialist consultations covered?"
])
# Add general suggestions if none specific
if not suggestions:
suggestions.extend([
"What is covered under this policy?",
"How do I file a claim?",
"What are the policy terms and conditions?",
"What documents do I need?"
])
return suggestions[:5] # Return top 5 suggestions
except Exception as e:
logger.error(f"Error generating query suggestions: {e}")
return []
# Example usage
if __name__ == "__main__":
parser = AdvancedQueryParser()
# Test queries
test_queries = [
"Is heart surgery covered?",
"How do I file a claim?",
"What's the waiting period?",
"Can I claim for dental treatment?",
"What documents are needed?"
]
for query in test_queries:
print(f"\n{'='*50}")
print(f"Original Query: {query}")
parsed = parser.parse_query(query)
print(f"Enhanced Query: {parsed.enhanced_query}")
print(f"Query Type: {parsed.query_type}")
print(f"Intent: {parsed.intent}")
print(f"Confidence: {parsed.confidence:.2f}")
print(f"Entities: {parsed.entities}")
print(f"Keywords: {parsed.keywords}")
suggestions = parser.get_query_suggestions(query)
print(f"Suggestions: {suggestions[:2]}") |