Back to Projects
    LLM
    RAG
    NLP
    Chatbot

    Conversational AI Customer Service Bot

    LLM-powered chatbot with RAG capabilities handling 80% of customer inquiries automatically.

    Overview

    Built an intelligent customer service chatbot using large language models with Retrieval-Augmented Generation (RAG). The system understands context, maintains conversation history, and provides accurate responses by retrieving relevant information from company knowledge bases. Integrated with existing CRM and ticketing systems.

    Code Highlight

    RAG-Enhanced Conversational AI
    from langchain.llms import OpenAI
    from langchain.embeddings import OpenAIEmbeddings
    from langchain.vectorstores import Chroma
    from langchain.chains import ConversationalRetrievalChain
    from langchain.memory import ConversationBufferWindowMemory
    class ConversationalAI:
    def __init__(self, knowledge_base_path: str):
    self.llm = OpenAI(temperature=0.7, model="gpt-4")
    self.embeddings = OpenAIEmbeddings()
    self.vectorstore = Chroma(
    persist_directory=knowledge_base_path,
    embedding_function=self.embeddings
    )
    self.memory = ConversationBufferWindowMemory(
    memory_key="chat_history",
    return_messages=True,
    k=10 # Remember last 10 exchanges
    )
    # Create retrieval chain with custom prompt
    self.chain = ConversationalRetrievalChain.from_llm(
    llm=self.llm,
    retriever=self.vectorstore.as_retriever(search_kwargs={"k": 5}),
    memory=self.memory,
    return_source_documents=True
    )
    async def process_query(self, user_query: str, session_id: str) -> dict:
    """Process user query with context retrieval"""
    try:
    # Add intent classification
    intent = await self.classify_intent(user_query)
    # Route to specialized handlers for complex requests
    if intent in ['billing', 'technical_support', 'account_management']:
    return await self.handle_specialized_query(user_query, intent)
    # Standard RAG processing
    result = await self.chain.arun({"question": user_query})
    return {
    'response': result['answer'],
    'confidence': self.calculate_confidence(result),
    'sources': [doc.metadata for doc in result['source_documents']],
    'intent': intent,
    'requires_human': self.should_escalate(result, intent)
    }
    except Exception as e:
    return {
    'response': "I apologize, but I'm having trouble processing your request. Let me connect you with a human agent.",
    'requires_human': True,
    'error': str(e)
    }
    def calculate_confidence(self, result: dict) -> float:
    """Calculate response confidence based on retrieval quality"""
    source_scores = [doc.metadata.get('score', 0) for doc in result.get('source_documents', [])]
    return np.mean(source_scores) if source_scores else 0.5

    Key Results

    80% automated resolution rate
    90% customer satisfaction score
    50% reduction in support tickets
    24/7 multilingual support

    Technologies Used

    Python
    OpenAI GPT
    LangChain
    ChromaDB
    FastAPI
    WebSocket
    Redis

    Project Category

    ai automation

    Repository

    View on GitHub