Data Wizardry – Unleashing Live Insights with OpenAI, LangChain & SAP HANA

Lets jump right in with an actual question I just gave to a Hana Cloud Database:

Natural%20Language%20question

 

The response I got back was correct :

Natural%20Language%20answer

 

Ok so you’re guessing I used ChatGPT, so  it’s either hallucinating and made a lucky guess, or perhaps I pre-loaded the data (context)  into ChatGPT and it just summarised the results for me.

 

Nope.

 

I utilsed  OpenAI’s API’s to converted the question into SQL, the SQL was then executed on a Hana Cloud instance and the results were then further summarised by OpenAI.  LangChain’s SQLDatabaseChain does most of the work.

Heres the full interaction:

Click%20to%20Enlarge

Click to Enlarge

 

Bonus Points to anyone who noticed I ‘deliberately’ miss-spelt Australia in the question.  It wasn’t a significant obstacle for OpenAI.

 

The SQL generated really does run in Hana:

Click%20to%20Enlarge

Click to Enlarge

 

The data flow is approximately like this:

Dataflow

 

The sample code is here:

https://github.com/amacdexp/LangChainHanaSQL.git

 

 

The main inspirations and references include:

https://blog.langchain.dev/llms-and-sql/

https://python.langchain.com/en/latest/modules/chains/examples/sqlite.html

https://github.com/SAP/sqlalchemy-hana

 

So as you can see it’s now possible to ask Hana questions in Natural language.

I hope you found this glimpse of a potential future interesting.

 

What use case would you find this useful for?

Original Article:
https://blogs.sap.com/2023/05/31/data-wizardry-unleashing-live-insights-with-openai-langchain-sap-hana/

ASK SAP EXPERTS ONLINE
Related blogs

LEAVE A REPLY

Please enter your comment!
Please enter your name here