{"id":12417,"date":"2021-11-08T12:38:53","date_gmt":"2021-11-08T20:38:53","guid":{"rendered":"https:\/\/www.couchbase.com\/blog\/?p=12417"},"modified":"2025-06-13T21:25:11","modified_gmt":"2025-06-14T04:25:11","slug":"ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics","status":"publish","type":"post","link":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/","title":{"rendered":"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics"},"content":{"rendered":"<p><span style=\"font-weight: 400\">After conversations with our customers about the delay in obtaining analytical insights from their Python-based machine learning models, we set out to create a seamless pipeline from Python to Couchbase Analytics that returns faster insights in real time.\u00a0<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Introduction<\/span><\/h3>\n<p><span style=\"font-weight: 400\">With the release of <\/span><a href=\"https:\/\/www.couchbase.com\/products\/server\/whats-new\/\"><span style=\"font-weight: 400\">Couchbase Server 7.0<\/span><\/a><span style=\"font-weight: 400\">, we\u2019re excited to launch a new feature that you can explore in <\/span><b>Developer Preview mode<\/b><span style=\"font-weight: 400\">: integration of Python UDFs with Couchbase Analytics.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400\">Machine Learning has radically transformed the ways in which organizations understand their customer\u2019s needs. Advanced analytics domains like predictive analytics (customer churn, customer sentiment, etc.) and financial modeling are growing more reliant on processing data at scale, near real-time and extracting valuable insights from it.<\/span><\/p>\n<p><span style=\"font-weight: 400\">This blog will walk through the process of setting up Couchbase instances, syncing to the remote AnalyticsML repository, creating the needed directories, and running the needed code samples.<\/span><\/p>\n<p><span style=\"font-weight: 400\">The intended audience for this blog is anyone casually interested in the intersection of Couchbase Server, Machine Learning, Python, and the Couchbase Analytics service. There are certain concepts presented that we expect the reader to understand (but don\u2019t worry, we will embed links to get you up to speed). Overall, we want anyone who has even the mildest interest to walk through this tutorial to see how the power of ML can be focused on data resident in Couchbase using their ML algorithms to gain instant insights.<\/span><\/p>\n<h3><span style=\"font-weight: 400\">Prerequisites And Assumptions:<\/span><\/h3>\n<h4><span style=\"font-weight: 400\">Knowledge\/understanding:<\/span><\/h4>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Couchbase Server: <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/learn\/architecture-overview.html\"><span style=\"font-weight: 400\">https:\/\/docs.couchbase.com\/server\/current\/learn\/architecture-overview.html<\/span><\/a><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Installing Couchbase Server on Docker: <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/install\/getting-started-docker.html#multi-node-cluster-one-host\"><span style=\"font-weight: 400\">https:\/\/docs.couchbase.com\/server\/current\/install\/getting-started-docker.html#multi-node-cluster-one-host<\/span><\/a><span style=\"font-weight: 400\">\u00a0<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Couchbase Analytics: <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/analytics\/introduction.html\"><span style=\"font-weight: 400\">https:\/\/docs.couchbase.com\/server\/current\/analytics\/introduction.html<\/span><\/a><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Sentiment Analysis using Sci-kit Learn: <\/span><a href=\"https:\/\/scikit-learn.org\/stable\/tutorial\/basic\/tutorial.html\"><span style=\"font-weight: 400\">https:\/\/scikit-learn.org\/stable\/tutorial\/basic\/tutorial.html<\/span><\/a><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4><span style=\"font-weight: 400\">Environment Configuration:<\/span><\/h4>\n<p><span style=\"font-weight: 400\">Additionally, in order to follow along with the below steps, you\u2019ll need a functioning Couchbase implementation:<\/span><\/p>\n<ul>\n<li style=\"list-style-type: none\">\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">An existing Python v3.8+ IDE of choice (I will use VSCode for this blog).<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Docker Desktop installed on your computer<\/span><\/li>\n<li style=\"font-weight: 400\">\n<pre class=\"\">The code samples will be formatted to indicate what should be included in your sample<\/pre>\n<\/li>\n<li style=\"font-weight: 400\"><i><span style=\"font-weight: 400\">The command line samples will be formatted in <\/span><\/i><i><span style=\"font-weight: 400\">italics<\/span><\/i><i><span style=\"font-weight: 400\"> to denote what should be entered<\/span><\/i><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Within the Python examples, all the needed libraries are identified (sklearn is from scikit-learn). If you do not have those libraries, please install them with \u2018<\/span><i><span style=\"font-weight: 400\">pip3 install &lt;library name&gt;<\/span><\/i><span style=\"font-weight: 400\">\u2019<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The two datasets used for this blog can be found on kaggle at (<\/span><a href=\"https:\/\/www.kaggle.com\/stefanoleone992\/rotten-tomatoes-movies-and-critic-reviews-dataset\"><span style=\"font-weight: 400\">https:\/\/www.kaggle.com\/stefanoleone992\/rotten-tomatoes-movies-and-critic-reviews-dataset<\/span><\/a><span style=\"font-weight: 400\">). These are rather large files so a link to them is provided so you can download them when you follow along.<\/span><\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h4><span style=\"font-weight: 400\">Setting Up Your Couchbase Server:<\/span><\/h4>\n<p><span style=\"font-weight: 400\">In this section, you will install and configure your Couchbase Server.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">From your terminal command line, create the nodes (\u2018cb-analytics\u2019 &amp; \u2018cb\u2019):<\/span>\n<ol>\n<li style=\"font-weight: 400\">\n<pre class=\"\">docker run -d --name cb-analytics couchbase:7.0.2<\/pre>\n<\/li>\n<li style=\"font-weight: 400\">\n<pre class=\"\">docker run -d --name cb -p 8091-8096:8091-8096 -p 11210-11211:11210-11211 couchbase<\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">To confirm the instance was launched successfully:<\/span>\n<ol>\n<li><span style=\"font-weight: 400\">docker logs db1<\/span><\/li>\n<li><\/li>\n<\/ol>\n<\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">If the container has started, the output should start with the following:<\/span>\n<ol>\n<li>\n<pre>Starting Couchbase Server -- Web UI available at https:\/\/:8091<\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Discover the local IP addresses of cb and cb-analytics:<\/span>\n<ol>\n<li style=\"font-weight: 400\">\n<pre>docker inspect --format '{{ .NetworkSettings.IPAddress }}' cb<\/pre>\n<\/li>\n<li style=\"font-weight: 400\">\n<pre>docker inspect --format '{{ .NetworkSettings.IPAddress }}' cb-analytics<\/pre>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12418 size-large\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/pythonudf-1024x175.png\" alt=\"\" width=\"900\" height=\"154\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf-1024x175.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf-300x51.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf-768x131.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf-1536x262.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf-20x3.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf-1320x225.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/pythonudf.png 1600w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<p><span style=\"font-weight: 400\">5. Go to <\/span><i><span style=\"font-weight: 400\">https:\/\/ localhost:8091<\/span><\/i><span style=\"font-weight: 400\"> to start the setup of your couchbase instance and select \u2018<\/span><i><span style=\"font-weight: 400\">Setup New Cluste<\/span><\/i><span style=\"font-weight: 400\">r\u2019 and proceed through the Setup Wizard as normal:<\/span><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12419 size-large\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/server-1024x684.png\" alt=\"\" width=\"900\" height=\"601\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server-1024x684.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server-300x200.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server-768x513.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server-400x267.png 400w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server-450x300.png 450w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server-20x13.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/server.png 1060w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<ol>\n<li style=\"list-style-type: none\"><\/li>\n<\/ol>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The Couchbase Server names are <\/span><b>\u2018cb<\/b><span style=\"font-weight: 400\">\u2019 and \u2018<\/span><b>cb-analytics<\/b><span style=\"font-weight: 400\">\u2019 with user name <em>\u2018<\/em><\/span><em><span style=\"font-weight: 400\">Administrator<\/span><\/em><span style=\"font-weight: 400\"><em>\u2019<\/em> and password \u2018<\/span><em><span style=\"font-weight: 400\">password<\/span><\/em><span style=\"font-weight: 400\">\u2019<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">After the cluster is initialized on the first Couchbase Server node (cb), the next step is to add the Couchbase Server nodes from cb-analytics to the cluster.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">In the Couchbase Web Console, go to the Servers tab and click ADD SERVER. This opens the \u2018Add Server Node\u2019 dialog.<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12420 size-large\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/servernode-776x1024.png\" alt=\"\" width=\"776\" height=\"1024\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/servernode-776x1024.png 776w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/servernode-227x300.png 227w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/servernode-768x1013.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/servernode-300x396.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/servernode-15x20.png 15w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/servernode.png 1060w\" sizes=\"auto, (max-width: 776px) 100vw, 776px\" \/><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">In the Hostname\/IP Address field, enter the IP address that you previously captured for cb. Click Add Server to add the node to the cluster configuration.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">After cb and cb-analytics are successfully added to the cluster configuration, click Rebalance to make the new nodes active in the cluster.<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">Create two buckets, one for \u2018movies\u2019 and one for \u2018movie_reviews\u2019:<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12421 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/databucket.png\" alt=\"\" width=\"531\" height=\"438\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/databucket.png 531w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/databucket-300x247.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/databucket-20x16.png 20w\" sizes=\"auto, (max-width: 531px) 100vw, 531px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12422 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/databucket2.png\" alt=\"\" width=\"530\" height=\"436\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/databucket2.png 530w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/databucket2-300x247.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/databucket2-20x16.png 20w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">You now have a multi-node Couchbase cluster running in containers on a single host. Your two buckets and your Couchbase instance are ready to run (if you need more details, here is the link to the <\/span><a href=\"https:\/\/docs.couchbase.com\/server\/current\/install\/getting-started-docker.html#multi-node-cluster-one-host\"><span style=\"font-weight: 400\">steps in more detail<\/span><\/a><span style=\"font-weight: 400\">).\u00a0<\/span><\/li>\n<\/ul>\n<p><b>WARNING: COUCHBASE SERVER MUST BE IN DEVELOPER PREVIEW MODE. SETTING COUCHBASE SERVER TO THIS MODE IS A NON-RECOVERABLE CHANGE AND IT IS STRONGLY RECOMMENDED NOT TO MAKE THIS CHANGE TO A PRODUCTION ENVIRONMENT OR CRITICAL SYSTEM.\u00a0<\/b><\/p>\n<p><span style=\"font-weight: 400\">Setting up Couchbase Server in Developer Preview mode requires you to run the following in a command line.<\/span><\/p>\n<pre>\/opt\/couchbase\/bin\/couchbase-cli enable-developer-preview -c localhost:8091 -u Administrator \\ -p password --enable<\/pre>\n<h4><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12423 size-large\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/password-enable-1024x122.png\" alt=\"\" width=\"900\" height=\"107\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable-1024x122.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable-300x36.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable-768x91.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable-1536x182.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable-20x2.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable-1320x157.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/password-enable.png 1600w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/h4>\n<p><span style=\"font-weight: 400\">Setting Up Your File System:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">The files for this exercise and training dataset can be found within the <\/span><a href=\"https:\/\/github.com\/couchbaselabs\/AnalyticsML\"><span style=\"font-weight: 400\">github repo<\/span><\/a><span style=\"font-weight: 400\">\u00a0<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12424 size-large\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/githubrepo-1024x159.png\" alt=\"\" width=\"900\" height=\"140\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo-1024x159.png 1024w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo-300x47.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo-768x120.png 768w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo-1536x239.png 1536w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo-20x3.png 20w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo-1320x205.png 1320w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/githubrepo.png 1600w\" sizes=\"auto, (max-width: 900px) 100vw, 900px\" \/><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\">You will need to create a folder to work within to keep your contents separate from your other activities (i.e. examples\/AnalyticsML) and within that folder you will need to create another folder called \u2018<\/span><i><span style=\"font-weight: 400\">pipeline<\/span><\/i><span style=\"font-weight: 400\">\u2019.<\/span><\/li>\n<\/ul>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-12425 size-full\" src=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2021\/11\/github.png\" alt=\"\" width=\"687\" height=\"156\" srcset=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/github.png 687w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/github-300x68.png 300w, https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/github-20x5.png 20w\" sizes=\"auto, (max-width: 687px) 100vw, 687px\" \/><\/p>\n<p>You just set up the needed Couchbase Server environment on Docker. In Part 2, we will set up the needed code samples, import the function and finally run the sentiment analysis function from Couchbase Analytics.<\/p>\n<p><span style=\"font-weight: 400\">Want to learn more about Couchbase Analytics? Watch the full ConnectONLINE session here:<\/span><\/p>\n<p><iframe loading=\"lazy\" title=\"Machine Learning Meets NoSQL: Python UDFs - CBConnect21\" width=\"900\" height=\"506\" src=\"https:\/\/www.youtube.com\/embed\/nyHUKfTMKDQ?feature=oembed&#038;enablejsapi=1&#038;origin=https:\/\/www.couchbase.com\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<p><b data-stringify-type=\"bold\">Acknowledgments<\/b><br \/>\nThanks to\u00a0<b data-stringify-type=\"bold\">Anuj Kothari,\u00a0<\/b>a summer Product Management Intern for Couchbase Analytics service, who\u2019s initial efforts got this started and off the ground last summer. Thanks to\u00a0<b data-stringify-type=\"bold\">Idris Motiwala<\/b>, Principal Product Manager on the Couchbase Analytics Service, and\u00a0<b data-stringify-type=\"bold\">Ian Maxon<\/b>, a software engineer for the Couchbase Analytics Service, for their editorial work in making this a more functional blog.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>After conversations with our customers about the delay in obtaining analytical insights from their Python-based machine learning models, we set out to create a seamless pipeline from Python to Couchbase Analytics that returns faster insights in real time.\u00a0 Introduction With [&hellip;]<\/p>\n","protected":false},"author":79257,"featured_media":12429,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"footnotes":""},"categories":[2294,1816,9139,1812],"tags":[8907,1519,2140,1725],"ppma_author":[9482,9483],"class_list":["post-12417","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-analytics","category-couchbase-server","category-python","category-n1ql-query","tag-couchbase-server-7-0","tag-docker","tag-machine-learning","tag-nosql-database"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics - The Couchbase Blog<\/title>\n<meta name=\"description\" content=\"Learn about a new feature that you can explore in Developer Preview mode: integration of Python UDFs with Couchbase Analytics\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics\" \/>\n<meta property=\"og:description\" content=\"Learn about a new feature that you can explore in Developer Preview mode: integration of Python UDFs with Couchbase Analytics\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\" \/>\n<meta property=\"og:site_name\" content=\"The Couchbase Blog\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-08T20:38:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-14T04:25:11+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2560\" \/>\n\t<meta property=\"og:image:height\" content=\"1707\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Muk Sreenivasan, Anuj Kothari\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Muk Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\"},\"author\":{\"name\":\"Muk Sreenivasan\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/b37fc76b5459210102cef15674423031\"},\"headline\":\"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics\",\"datePublished\":\"2021-11-08T20:38:53+00:00\",\"dateModified\":\"2025-06-14T04:25:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\"},\"wordCount\":890,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg\",\"keywords\":[\"Couchbase Server 7.0\",\"docker\",\"Machine Learning (ML)\",\"NoSQL Database\"],\"articleSection\":[\"Couchbase Analytics\",\"Couchbase Server\",\"Python\",\"SQL++ \/ N1QL Query\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\",\"name\":\"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics - The Couchbase Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg\",\"datePublished\":\"2021-11-08T20:38:53+00:00\",\"dateModified\":\"2025-06-14T04:25:11+00:00\",\"description\":\"Learn about a new feature that you can explore in Developer Preview mode: integration of Python UDFs with Couchbase Analytics\",\"breadcrumb\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg\",\"width\":2560,\"height\":1707},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.couchbase.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#website\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"name\":\"The Couchbase Blog\",\"description\":\"Couchbase, the NoSQL Database\",\"publisher\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#organization\",\"name\":\"The Couchbase Blog\",\"url\":\"https:\/\/www.couchbase.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png\",\"width\":218,\"height\":34,\"caption\":\"The Couchbase Blog\"},\"image\":{\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/b37fc76b5459210102cef15674423031\",\"name\":\"Muk Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/194f54236bbc53ba3b1b5550c654d008\",\"url\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/muk_sreenivasan.png\",\"contentUrl\":\"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/muk_sreenivasan.png\",\"caption\":\"Muk Sreenivasan\"},\"url\":\"https:\/\/www.couchbase.com\/blog\/author\/muk-sreenivasan\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics - The Couchbase Blog","description":"Learn about a new feature that you can explore in Developer Preview mode: integration of Python UDFs with Couchbase Analytics","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/","og_locale":"en_US","og_type":"article","og_title":"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics","og_description":"Learn about a new feature that you can explore in Developer Preview mode: integration of Python UDFs with Couchbase Analytics","og_url":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/","og_site_name":"The Couchbase Blog","article_published_time":"2021-11-08T20:38:53+00:00","article_modified_time":"2025-06-14T04:25:11+00:00","og_image":[{"width":2560,"height":1707,"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg","type":"image\/jpeg"}],"author":"Muk Sreenivasan, Anuj Kothari","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Muk Sreenivasan","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#article","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/"},"author":{"name":"Muk Sreenivasan","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/b37fc76b5459210102cef15674423031"},"headline":"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics","datePublished":"2021-11-08T20:38:53+00:00","dateModified":"2025-06-14T04:25:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/"},"wordCount":890,"commentCount":0,"publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg","keywords":["Couchbase Server 7.0","docker","Machine Learning (ML)","NoSQL Database"],"articleSection":["Couchbase Analytics","Couchbase Server","Python","SQL++ \/ N1QL Query"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/","url":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/","name":"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics - The Couchbase Blog","isPartOf":{"@id":"https:\/\/www.couchbase.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage"},"thumbnailUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg","datePublished":"2021-11-08T20:38:53+00:00","dateModified":"2025-06-14T04:25:11+00:00","description":"Learn about a new feature that you can explore in Developer Preview mode: integration of Python UDFs with Couchbase Analytics","breadcrumb":{"@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#primaryimage","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/luca-bravo-XJXWbfSo2f0-unsplash-scaled.jpg","width":2560,"height":1707},{"@type":"BreadcrumbList","@id":"https:\/\/www.couchbase.com\/blog\/ml-meets-nosql-integrating-python-user-defined-functions-with-n1ql-for-analytics\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.couchbase.com\/blog\/"},{"@type":"ListItem","position":2,"name":"ML Meets NoSQL: Integrating Python User-Defined Functions with SQL++ for Analytics"}]},{"@type":"WebSite","@id":"https:\/\/www.couchbase.com\/blog\/#website","url":"https:\/\/www.couchbase.com\/blog\/","name":"The Couchbase Blog","description":"Couchbase, the NoSQL Database","publisher":{"@id":"https:\/\/www.couchbase.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.couchbase.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.couchbase.com\/blog\/#organization","name":"The Couchbase Blog","url":"https:\/\/www.couchbase.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/2023\/04\/admin-logo.png","width":218,"height":34,"caption":"The Couchbase Blog"},"image":{"@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/b37fc76b5459210102cef15674423031","name":"Muk Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.couchbase.com\/blog\/#\/schema\/person\/image\/194f54236bbc53ba3b1b5550c654d008","url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/muk_sreenivasan.png","contentUrl":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/muk_sreenivasan.png","caption":"Muk Sreenivasan"},"url":"https:\/\/www.couchbase.com\/blog\/author\/muk-sreenivasan\/"}]}},"authors":[{"term_id":9482,"user_id":79257,"is_guest":0,"slug":"muk-sreenivasan","display_name":"Muk Sreenivasan","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/muk_sreenivasan.png","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2022\/03\/muk_sreenivasan.png"},"author_category":"","last_name":"Sreenivasan","first_name":"Muk","job_title":"","user_url":"","description":"Muk is a Senior Sales Engineer at Couchbase covering the west coast of the United States. He has over 20 years experience in product support, product development, product management and Sales. He lives and works in Silicon Valley."},{"term_id":9483,"user_id":0,"is_guest":1,"slug":"anuj-kothari","display_name":"Anuj Kothari","avatar_url":{"url":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/Screen-Shot-2021-11-08-at-12.21.36-PM.png","url2x":"https:\/\/www.couchbase.com\/blog\/wp-content\/uploads\/sites\/1\/2021\/11\/Screen-Shot-2021-11-08-at-12.21.36-PM.png"},"author_category":"","last_name":"Kothari","first_name":"Anuj","job_title":"","user_url":"","description":"Anuj Kothari was a Product Management Intern at Couchbase working on the Analytics service. He also has experience in consulting, data science, and competitive debate. He is currently pursuing his undergraduate education in computer science and economics at the University of Pennsylvania. "}],"_links":{"self":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/12417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/users\/79257"}],"replies":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/comments?post=12417"}],"version-history":[{"count":0,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/posts\/12417\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media\/12429"}],"wp:attachment":[{"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/media?parent=12417"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/categories?post=12417"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/tags?post=12417"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.couchbase.com\/blog\/wp-json\/wp\/v2\/ppma_author?post=12417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}