Session Explorer in Action: Personalizing Conference Experiences with AI Using Vector Support in Azure SQL, LangChain, and Streamlit

Conferences can be overwhelming, with countless sessions, various speakers, and a wealth of information to digest. What if we could simplify this experience using AI, turning data into a personalized assistant? Enter Session Explorer, a cutting-edge solution built using Vector Support in Azure SQL, LangChain, and Streamlit. This AI-powered application transforms the way attendees interact with conference data, making it intuitive, efficient, and engaging.

The Inspiration Behind Session Explorer

Conferences like the PASS Data Community Summit bring together diverse topics, speakers, and attendees. While the variety is exciting, navigating this wealth of information can be daunting. The Session Explorer was designed to:

  • Help attendees quickly find relevant sessions.
  • Provide insights about specific speakers or topics.
  • Create a seamless, user-friendly interface powered by AI.

By leveraging Vector Support in Azure SQL for intelligent data retrieval, LangChain for conversational AI, and Streamlit for a dynamic user interface, the app makes conference exploration smarter and simpler.

Key Technologies Powering Session Explorer

1. Vector Support in Azure SQL

Azure SQL’s vector capabilities enable efficient semantic searches by transforming text into embeddings. These embeddings are compared using the vector_distance function, allowing the system to find similar sessions based on user queries.

Here’s how it works:

SQL
DECLARE @qv vector(1536);
EXEC web.get_embedding 'Data-driven insights', @qv OUTPUT;

SELECT TOP(5) 
    se.id AS session_id, 
    vector_distance('cosine', se.embeddings, @qv) AS distance
FROM 
    web.sessions se
ORDER BY
    distance;

This query takes a user-provided text, converts it to an embedding using OpenAI, and retrieves the most relevant sessions.

If you want to know more about Vector Support in Azure SQL go to my post below.

2. LangChain

LangChain integrates the retrieval-augmented generation (RAG) approach to provide additional context to the language model. Using LCEL (LangChain Expression Language), it dynamically injects session data into prompts for personalized responses.

Python
prompt = ChatPromptTemplate.from_messages(
    [
        (
            "ai",
            """ 
            You are a system assistant who helps users find all sessions related to watch from the conference, based off the sessions that are provided to you.
            Sessions will be provided in an assistant message in the format of `title|abstract|speakers|start-time|end-time|room|track|session_type|topics|level|Session URL`. You can use only the provided session list to help you answer the user's question.
            if the user asks about a speaker, you can respond with the sessions that the speaker is participating in.
            If the user asks a question that is not related to the provided sessions, you can respond with a message that I'm unable to assist with that question because the information you're asking for is not available in the database..
            Your answer must have the session title, a very short summary of the abstract, the speakers, the start time, the end time, the room, track, session type topic and level. In the end insert the session URL to open in a new windows.
            """,
        ),
        (
            "human", """
            The sessions available at the conference are the following: 
            {sessions}                
            """
        ),
        (
            "human", 
            "{question}"
        ),
    ]
)

retriever = RunnableLambda(get_similar_sessions).bind() 

rag_chain = {"sessions": retriever, "question": RunnablePassthrough()} | prompt | llm

3. Streamlit

Streamlit creates an intuitive web interface, making the AI capabilities accessible to users. With a few lines of code, we crafted an interactive app where users can ask questions and receive detailed session recommendations.

Python
import streamlit as st
import os
import sys
from dotenv import load_dotenv
import logging
from utilities import get_similar_sessions
from langchain_openai import ChatOpenAI
from langchain.prompts import ChatPromptTemplate
from langchain.schema import StrOutputParser
from langchain.schema.runnable import Runnable
from langchain.schema.runnable.config import RunnableConfig
from langchain_core.runnables import RunnableLambda
from langchain_core.runnables import RunnablePassthrough
import getpass

logging.basicConfig(level=logging.INFO)

# Adicionando o diretório pai ao caminho
sys.path.append(os.path.abspath('..'))

# Carrega as variáveis de ambiente do arquivo .env
load_dotenv()

if not os.environ.get("OPENAI_API_KEY"):
    os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter your OpenAI API key: ")

MODELO = ""

prompt = ChatPromptTemplate.from_messages(
    [
        (
            "ai",
            """ 
            You are a system assistant who helps users find all sessions related to watch from the conference, based off the sessions that are provided to you.
            Sessions will be provided in an assistant message in the format of `title|abstract|speakers|start-time|end-time|room|track|session_type|topics|level|Session URL`. You can use only the provided session list to help you answer the user's question.
            if the user asks about a speaker, you can respond with the sessions that the speaker is participating in.
            If the user asks a question that is not related to the provided sessions, you can respond with a message that I'm unable to assist with that question because the information you're asking for is not available in the database..
            Your answer must have the session title, a very short summary of the abstract, the speakers, the start time, the end time, the room, track, session type topic and level. In the end insert the session URL to open in a new windows.
            """,
        ),
        (
            "human", """
            The sessions available at the conference are the following: 
            {sessions}                
            """
        ),
        (
            "human", 
            "{question}"
        ),
    ]
)

def configure_app():
    """Configura a aparência e o layout do aplicativo Streamlit."""
    st.set_page_config(
        page_title="Chat",
        page_icon="💬",
        layout="wide",
        initial_sidebar_state="expanded",
    )
    st.header('Session Explorer: Your Guide to the Data Pass Summit 2024')

    st.write("""Ask something like 'What are the sessions about Azure SQL and AI?' or 'What are the sessions by Davide Mauri?'""")
        
def sidebar_inputs():
    """Exibe o menu lateral para inserção das informações do administrador e upload do arquivo."""
    with st.sidebar:        
        
        st.image("https://passdatacommunitysummit.com/assets/images/pass-2024-logo-lock-up--dark--with-icon.svg")   
        
        # Opção de seleção entre Open AI e Groq para definir o modelo
        modelo = st.selectbox("Select the model:", ('gpt-4o-mini','gpt-4o' ))
                         
        ""

        "You can find more information about this app in my blog post: [Session Explorer in Action: Personalizing Conference Experiences with AI Using Vector Support in Azure SQL, LangChain, and Streamlit](https://lawrence.eti.br/2024/11/20/session-explorer-in-action-personalizing-conference-experiences-with-ai-using-vector-support-in-azure-sql-langchain-and-streamlit/)"
        ""
        "The PASS Data Community Summit is an annual conference designed for data professionals to connect, share insights, and learn from peers and industry leaders. It focuses on a wide range of topics, including analytics, architecture, database management, development, and professional growth, across multiple platforms such as Microsoft, AWS, Google, PostgreSQL, and others."        
        ""
        "Official website: [PASS Data Community Summit](https://passdatacommunitysummit.com/)"
        ""	
        ""
        ""
        "Created by [Lawrence Teixeira](https://www.linkedin.com/in/lawrenceteixeira/)"

    return modelo        
        
def main():    
    """Função principal do aplicativo, onde todas as funções são chamadas."""
        
    configure_app()
            
    global MODELO

    modelo = sidebar_inputs()
    
    MODELO = modelo

    llm = ChatOpenAI(
        model=MODELO,
        temperature=0,
        max_tokens=16383,
        timeout=None,
        max_retries=2,
        streaming=False,
    )

    if "messages" not in st.session_state:
        st.session_state["messages"] = [{"role": "assistant", "content": "Hi! 😊 How are you? 💬 Feel free to ask anything about the sessions at PASS Data Community Summit 2024!"}]

    for msg in st.session_state.messages:
        if msg["role"] != "system":
            st.chat_message(msg["role"]).write(msg["content"])

    if prompt_entrada := st.chat_input("Type your message here"):
        st.session_state.messages.append({"role": "user", "content": prompt_entrada})
        st.chat_message("user").write(prompt_entrada)
        
        with st.spinner('Searching...'): 
            
            retriever = RunnableLambda(get_similar_sessions).bind() 

            rag_chain = {"sessions": retriever, "question": RunnablePassthrough()} | prompt | llm

            response_chat = rag_chain.invoke(prompt_entrada)            
            
            response = response_chat.content
        
        if response:
            result = (str(response))
        else:
            result = (str(":)"))

        msg = { "role": "assistant",
                "content": result
        }

        st.session_state.messages.append(msg)
                
        st.chat_message("assistant").write(msg["content"])    

if __name__ == "__main__":
    main()

How Session Explorer Works

Step 1: User Query

Users input a question, such as:
“Which sessions are led by John Doe?” or “What sessions discuss AI in data management?”

Step 2: Intelligent Retrieval

The app uses the get_similar_sessions function, querying Azure SQL with the user’s input. The SQL stored procedure returns a list of sessions ranked by relevance.

Python
results = cursor.execute("EXEC web.find_sessions @text=?", (search_text)).fetchall()

Step 3: Conversational AI

LangChain takes the retrieved data, formats it into a response template, and interacts with the language model to generate human-readable answers.

Step 4: Seamless Delivery

The personalized session details are displayed on the Streamlit interface, complete with clickable URLs to explore further.

Personalizing the Conference Experience

Here’s an example of a typical interaction:

  • User: “Show me all sessions by Dr. Smith.”
  • Session Explorer:
  • Title: “Advancing Data Science with AI”
  • Speakers: Dr. Smith, Jane Doe
  • Time: 10:00 AM – 11:30 AM
  • Room: Auditorium A
  • Track: Data Science
  • URL: Session Details

This level of personalization not only saves time but also enhances the conference experience by connecting attendees with sessions that truly matter to them.

If you want to try deploying the app yourself, visit my GitHub repository.

Introducing the Session Explorer App for PASS Data Community Summit 2024

The Session Explorer App is your go-to tool example for navigating the wealth of knowledge at the PASS Data Community Summit 2024. Built to streamline your conference experience, this app leverages the latest advancements in AI to help you discover sessions, speakers, and topics tailored to your interests.

What Can the App Do?

The app enables you to:

  • Explore Sessions: Ask specific questions about the available sessions, such as “What sessions discuss AI in data management?” or “Show me sessions by Dr. Smith.”
  • Discover Speakers: Find all sessions led by a particular speaker or group of speakers.
  • Plan Your Schedule: Get session details, including title, abstract, speakers, start and end times, room location, track, session type, and difficulty level.
  • Direct Access to Information: Each session includes a clickable link to its detailed page, making it easy to add it to your schedule.

How It Works

Using the app is simple:

  1. Click on this link: https://sessionschat.fly.dev/
  2. Ask a Question: Type your query into the chat interface, like “Which sessions are about Azure SQL?”
  3. Get Intelligent Responses: The app uses AI to understand your question and retrieve the most relevant session information from the database.
  4. View Results: Receive detailed session summaries, including timing, location, and a direct link to learn more.

Why Use the Session Explorer App?

The app transforms the way you navigate the conference, ensuring you never miss a session relevant to your goals. Whether you’re interested in AI, analytics, architecture, or professional development, the Session Explorer helps you focus on what matters most.

Experience the power of AI in personalizing your conference journey with the Session Explorer App. Dive into the sessions that spark your curiosity and make the most of the PASS Data Community Summit 2024!

Final Thoughts

The Session Explorer is more than just a chatbot; it’s a tool that redefines how we interact with conference data. Combining Vector Support’s power in Azure SQL, LangChain, and Streamlit delivers a personalized, AI-driven experience that attendees will love.

Whether you’re a data enthusiast, a tech professional, or an AI developer, the Session Explorer showcases the immense potential of AI in enhancing user experiences. Ready to explore it in action? Try it for yourself at the PASS Data Community Summit 2024 app!

That’s it for today!

Sources

https://devblogs.microsoft.com/azure-sql/build-a-chatbot-on-your-own-data-in-1-hour-with-azure-sql-langchain-and-chainlit/

https://github.com/Azure-Samples/azure-sql-db-rag-langchain-chainlit