Optimizing HR with LLMs+Langchain

In the current technology-driven world, industries are persistently looking for innovative solutions to modernize their operations and heighten efficiency. Technology advancements can play a significant role in the area of Human Resources (HR). The HR domain can streamline their processes with better efficiency by employing cutting-edge technologies such as Large Language Models (LLMs) and Langchain (a blockchain-based system for handling language data).

Being a Technology-First partner, Calsoft, always strive for what’s next in tech. Calsoft have implemented a transformative HR Ops tool: an HR-Copilot powered by Langchain. This Copilot assist employees in navigating company policies, accelerate the on boarding process, and provide instant, and conversationally accessible support.

Read the blog to explore how Calsoft achieved this and to delve deep into the technical foundations and the role Langchain played in the development of this HR Copilot. 

Introduction to Langchain 

Langchain is a versatile Python library designed to enable the building of applications employing LLMs for various tasks. It offers a suite of tools that make it simpler to interface with LLMs and to weave them into the flow of existing applications, data sources, and workflows. Langchain’s capabilities include conversational memory, retrieval mechanisms, and easy integration with document databases, which are pivotal for building a system like the Calsoft HR Copilot. 

Building the HR Copilot 

The Calsoft HR Copilot is intentionally built to offer automated, AI-driven conversational assistance to employees. Let’s look into the step-by-step breakdown of the development process, highlighting the relevance and contributions of Langchain at each stage: 

Step 1: Preparing the Dataset 

For AI Copilot the key part id data. This primarily include documents such as company policies, HR manuals, and FAQs in CSV, PDF, and TXT formats. The efficiency of AI-driven tool lies in its ability to understand and recover information from these documents. Langchain’s document loaders (CSVLoader, PyPDFLoader, TextLoader) and RecursiveCharacterTextSplitter are employed to process and split these documents into manageable chunks that can be later used by the LLM for question-answering tasks. 

Step 2: Embedding Documents with OpenAI 

The Chatbot should have a reliable source or location to look for answers before answering any questions. This needs embedding the documents to convert textual information into numerical vectors that are easily searchable. The OpenAIEmbeddings module of Langchain facilitates this by utilizing OpenAI’s powerful embedding models. 

Step 3: Storing and Retrieving Embeddings 

To efficiently retrieve relevant document segments, after generating embeddings with OpenAIEmbeddings, they are stored in a searchable index using Langchain’s FAISS vector store. Therefore, when an employee has a query, the HR Copilot can swiftly identify the most relevant part of the documents to craft an answer. 

Step 4: Engaging with ChatOpenAI and Conversational Retrieval 

In this step, Langchain’s ChatOpenAI and ConversationalRetrievalChain take center stage. ChatOpenAI is designed to manage the conversational aspect of the model (in this case, either GPT-3.5 or GPT-4), letting the Chatbot to maintain a natural dialogue with users. Concurrently, ConversationalRetrievalChain manages the retrieval of information from the stored document embeddings, fusing the outputs of LLMs and documents seamlessly for coherent, context-aware responses. 

Step 5: Creating a Custom Chatbot Class 

A custom Chatbot class accesses Langchain’s functions, providing methods to initialize the chat with greetings and pre-loaded context from the documents. This class uses templates from PromptTemplate to instruct the LLM on handling queries, ensuring that responses are restricted to the information from the provided documents. 

Step 6: Token Management and Usage Economy 

Langchain also allows monitoring token usage via get_openai_callback, ensuring that the AI’s operations remain within the budget and efficiency thresholds set by Calsoft. This is crucial for keeping the service cost-effective while upholding high standards of response quality. 

How It Works?

The HR Copilot have certain benefits including time savings, reduced overwhelm for HR staff, and empowered employees with instant access to critical information. The following discusses how this AI pilot works and which are the key enablers to realize this HR Copilot.  

Document Processing: 

HR-Copilot can handle various file types, including CSV, PDF, and TXT. 

Using Langchain’s document loaders (CSVLoader, PyPDFLoader, TextLoader), we efficiently process and extract text from these files. 

The RecursiveCharacterTextSplitter is employed to split the text into manageable chunks. 

Embeddings and Vector Store: 

To quickly retrieve of relevant information, we generate embeddings for the extracted text using OpenAI’s OpenAIEmbeddings. 

Langchain’s FAISS vector store is used to store and efficiently search through these embeddings. 

Chatbot Interaction: 

HR-Copilot engages employees in natural conversations using Langchain’s ConversationalRetrievalChain. 

The ChatOpenAI model powers the chatbot’s responses, ensuring accurate and contextually relevant answers. 

Langchain’s PromptTemplate allows for customizable prompts, guiding the chatbot’s behaviour. 

User Interface: 

The chatbot interface is built using Streamlit, a Python library for creating interactive web apps. 

Employees can easily interact with HR-Copilot, ask questions, and receive instant responses. 

The chat history is maintained using Streamlit’s session state, allowing for seamless conversation flow. 

Benefits: 

Time Savings

HR Copilot provides instant answers to common HR questions, reducing the time spent searching for information. 

New employees can quickly get up to speed, minimizing the need for extensive training sessions. 

Enhanced Learning: 

HR Copilot’s conversational interface makes learning about company policies more engaging and interactive. 

Employees can ask follow-up questions and receive clarification, ensuring a deeper understanding of the material. 

Scalability

As Calsoft grows, HR Copilot can easily scale to handle an increasing number of employees and documents. 

Langchain’s modular design enables easy integration of new data sources and models. 

In a Nutshell

Calsoft effectively built an HR Copilot by leveraging Langchain’s comprehensive set of tools. This Copilot can assist employees in real time, making the on boarding process faster and more interactive. The mix of conversational memory, document retrieval, efficient embedding techniques, and customizable prompt templates provided by Langchain were key to the system’s success. The implementation of Langchain’s functionalities into Calsoft’s HR infrastructure demonstrates the potential of leveraging AI for internal processes, showcasing a future where human resources can be managed with increased efficiency and sophistication. 

The Calsoft employees are now enjoying a more intuitive way of getting on boarded and staying informed about company policies with the HR Copilot. 

Interested in building a Copilot yourself? Reach out for a demo or consultation on how similar solutions can be integrated into your business operations.