avatarLaxfed Paulacy

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2102

Abstract

1 pm. As if that wasn’t enough, the girlfriend (my friend, was from an upper-middle-class family).</p><h2 id="2aa9">His parents didn’t need money either, they lived very well and had a lot of assets.</h2><p id="652e">He and his girlfriend travelled a lot and had a lot of fun. They were made for each other. The years went by. More than 10 years after dating, both were part of each other’s family.</p><p id="1eb5">They weren’t married yet, but it was as if they were, he slept most nights at her house, and worked at his future mother-in-law’s restaurant at night, but only when he felt like it.</p><p id="b21d">During the day, he only wore suits, because of his job as a bank worker. Her mother bought him clothes. Of course, he didn’t need to pay anything. Well, it was time to think about marriage. They started making plans for the happiest day.</p><h2 id="f57f">And it’s not that the darn thing, he wins around 150,000 euros in the lottery again!</h2><p id="e4fa">OK perfect. So, let’s buy a flat. The future home was a T3, well located and new, I’ve been seeing the house with them and I really liked it. The problem is that the deal had to be done quickly, otherwise they would lose the house.</p><p id="9512">As the lottery money was not yet available, the parents and future in-laws advanced the cash. A month passed, two, three months, and still nothing of the lottery prize. However, one day I was passing by the bank branch where he worked (it was quite far from the city where we all lived), I decided to invite him for a coffee, but unfortunately he wasn’t there.</p><p id="807b">Parents and in-laws started to get worried and decided to investigate why there was so much delay in receiving the amount won in the game.</p><h2 id="21fa">They made the biggest tumble of their lives.</h2><p id="9a0f">There was no prize. He lied, he hadn’t won anything. Furious, they decided to go to his job and ask for an explanation. Well, he wasn’t there… I would even say, he was never there, he never worked there and nobody knew him.</p><p id="ab07">In shock, they went to the bank where he had an ac

Options

count and learned that the first prize he had won, about 15 years before, was also a lie.</p><p id="c58c">However, every day he left the house to go to work around 08:00 and for more than a decade, I myself often crossed paths with him at that time, when I (really) went to work.</p><p id="2e14">When we went out together, he always had stories to tell about his work, colleagues, and boss. No one knows what he did in his spare time. He said he read the newspaper and magazines in the car until it was time to go home. I don’t know if I can believe it, can I?</p><p id="72e5">The relationship ended, and she had the biggest heartbreak of her life. As punishment, his father bought him a new car, as the one he had was already old. So much luck in one person… I should have known! Maybe I got carried away by reading so many Scrooge books.</p><blockquote id="b7a4"><p>If I gave you 50 claps, it means I read your story in its entirety and liked it.</p></blockquote><div id="2553" class="link-block"> <a href="https://anthony-r.medium.com/list/f27bf248151d"> <div> <div> <h2>About Me Stories</h2> <div><h3>Edit description</h3></div> <div><p>anthony-r.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*2422b7875e173f1f83a36bb04a18539a22848d8e.jpeg)"></div> </div> </div> </a> </div><div id="6a7f" class="link-block"> <a href="https://anthony-r.medium.com/list/60d06611fe9d"> <div> <div> <h2>True & Incredible Stories</h2> <div><h3>Edit description</h3></div> <div><p>anthony-r.medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*00b07cbb9a854b6e6b92594e9f404827c5db2de2.jpeg)"></div> </div> </div> </a> </div></article></body>

LANGCHAIN — Can AI Experiences Be Built With LLMs and the Semantic Layer?

Technology offers us a unique opportunity, though rarely welcome, to practice patience. — Allan Lokos.

Building AI experiences with LangChain, LLMs, and the semantic layer offers a powerful way to leverage the capabilities of large language models for natural language processing and data querying. In this tutorial, we will focus on Cube’s integration with LangChain and demonstrate how to build a chat-based demo application using LLMs for natural language queries to a semantic layer.

Semantic document loader

Cube’s integration with LangChain introduces the document loader, which populates a vector database with embeddings derived from the data model of the semantic layer. This vector database can then be queried to find best-matching entities of the semantic layer. This is useful for matching free-form input, such as queries in natural language, with the views and their members in the data model.

The following code snippet demonstrates how to ingest metadata from Cube and populate the vector database using the CubeSemanticLoader:

def ingest_cube_meta():
    ...
    loader = CubeSemanticLoader(api_url, api_token)
    documents = loader.load()
    ...
    with open("vectorstore.pkl", "wb") as f:
        pickle.dump(vectorstore, f)

Chat-based demo app, dissected

The chat-based demo application showcases the interaction between the user, the vector database, LLMs, and the semantic layer. Let’s break down the key components of the demo application:

  1. LLM setup: Initializing the OpenAI model with the provided API key.
import ...
load_dotenv()
llm = OpenAI(
    temperature=0, 
    openai_api_key=os.environ.get("OPENAI_API_KEY"),
    verbose=True
)
  1. User input and vector store initialization: Getting user input and initializing the vector store.
question = st.text_input(
    "Your question: ",
    placeholder="Ask me anything ...",
    key="input"
)
if st.button("Submit", type="primary"):
    check_input(question)
    vectorstore = init_vectorstore()
  1. Querying the vector store: Querying the vector store for documents similar to the user’s question.
docs = vectorstore.similarity_search(question)
table_name = docs[0].metadata["table_name"]
column_docs = vectorstore.similarity_search(
    columns_question,
    filter=dict(table_name=table_name),
    k=15
)
  1. Building the prompt and calling OpenAI: Constructing the prompt and calling the OpenAI large language model.
prompt = CUBE_SQL_API_PROMPT.format(
    input_question=question,
    table_info=table_name,
    columns_info=columns,
    top_k=1000,
    no_answer_text=_NO_ANSWER_TEXT,
)
llm_answer = llm(prompt + PROMPT_POSTFIX)

By following these code snippets and examples, you can create your own chat-based demo application that leverages the semantic layer and LLMs for natural language queries to Cube’s SQL API.

Cube’s integration with LangChain provides a seamless interface for querying data using natural language. By abstracting the complexities of SQL and leveraging the power of LLMs, it provides builders of AI experiences with a user-friendly and error-prone approach to data access.

In conclusion, this tutorial has provided a glimpse into the integration of Cube with LangChain and the possibilities it offers for building AI experiences with LLMs and the semantic layer. By leveraging the strengths of both platforms, developers can create powerful AI applications that enable natural language interactions with complex data models.

Langchain
Semantic
Experiences
AI
Llms
Recommended from ReadMedium