How to Use OpenAI Semantic Search with Neo4j Graph Database in 6 Steps

Rakesh Patel
Rakesh Patel
February, 12 2024
How-to-Use-OpenAI-Semantic-Search-with-Neo4j-Graph-Database

By connecting OpenAI Semantic Search with Neo4j graph database, you can provide

  • Scalable and flexible search solution for enterprise-level businesses. This combination handles a large amount of data and complex relationships in a Neo4j graph database.
  • Enhanced search accuracy as compared to traditional text-based search algorithms like TF-IDF and Cosine Similarity Algorithm.

More than 75% of Fortune 100 companies are using Neo4j graph technology. Check this image for reference.

neo4j

In fact, most of our enterprise clients prefer using the Neo4j graph database in their software solution.

Reason?
Neo4j can easily handle transactional and analytical workloads.

And while developing enterprise-level software using OpenAI, we often need to retrieve data from the Neo4j graph database. This is mostly the case when we are developing a cloud-based software solution. In fact, recently, we have helped our enterprise clients in the US and Canada to use this advanced OpenAI semantic search technology to improve their search accuracy.

In this blog, you will learn step by step process on how to connect and use OpenAI semantic search with the Neo4j graph database. You need to follow these 6 simple steps.

6 Steps to Use OpenAI Semantic Search with Neo4j Graph Database

  1. Before Connecting OpenAI to the Neo4j Graph Database, You Will Need These Prerequisites

    First, you need to have a basic understanding of the Neo4j graph database and the Cypher query language.

    Along with that, you should have:

    • Python 3 installed on your system
    • Neo4j graph database set up and running
    • Necessary permissions to create nodes, relationships, and indexes in your Neo4j database.

    Ready?
    Sounds good.

    Now, the second step.

  2. Create Nodes and Relationships in Neo4j

    In this step, you need to create nodes in Neo4j by using the Cypher query language.

    For example, to create a node with the label “Person” and the property “name”:

    CREATE  (n:Person { name: "Georgia O'Keeffe" })

    Next, you need to create and define relationships between two different nodes.

    For example, use this code to create a relationship between two nodes in the graph database with the label “Person” and the relationship type “KNOWS”:

      MATCH   (a:Person), (b:Person)
      WHERE a.name =  "Edward Hopper" AND b.name = "Norman Rockwell"
      CREATE  (a)-[r:KNOWS]->(b)
    

    So far, we have created different nodes and defined the relation between them.

    Further, we will learn how to install OpenAI semantic search in step 3.

  3. Install OpenAI Semantic Search

    But, how do you install OpenAI Semantic Search in your Python environment?

    It is simple.
    You just need to use this one-line code to install the OpenAI Semantic Search library in your Python environment.

    pip install openai-semantic-search  

    Copy this code and run.

    Done?

    Now, let’s connect the recently installed OpenAI Semantic Search with Neo4j.

  4. Connect to Neo4j Database With OpenAI Semantic Search

    How do you connect Neo4j with OpenAI Semantic Search?

    First, you need to import the OpenAI Semantic Search library in your Python script.
    Then, connect to your Neo4j database.

    When you connect your Neo4j database, you need to provide these two details:

    1. Database URL
    2. Credentials

    Use the following code to establish a connection to the Neo4j database.

    from openai_semantic_search import SemanticSearch

    ss = SemanticSearch(neo4j_url= "bolt://localhost:7687", neo4j_username="neo4j", neo4j_password="password")

    That’s it.
    If you have properly followed these 4 steps, you have successfully connected OpenAI with the Neo4j graph database.

    The ground is ready now.
    In the next step, you will learn a simple use case.

  5. Use OpenAI Semantic Search With Neo4j

    Now, let’s use the search method of the SemanticSearch object.

    Purpose?
    To search the Neo4j database and find the required items.

    Remember: We will be using natural language queries here.

    For example, to search for nodes with the label “Person” and the property “name” containing the keyword “Andy Warhol”:

    result = ss.search("Person named Andy Warhol", labels=["Person"], properties=["name"]) print(result)

    The purpose of this code is to retrieve nodes from the Neo4j database.
    Now, we will visualize this result to get a better understanding.

  6. Visualize the Relationship Between Nodes

    To visualize the results, you need to take these steps.

    • Import data into the database
    • Use the browser’s query editor to create a visual and comprehensive representation of the nodes and relationships.
    • Use this query to fetch nodes labeled as “Person” and the relationship between them MATCH (n:Person)-[r]->(m:Person) RETURN n,r,m
    • Run and click on the “View” to see a visual representation between nodes and relationships.

    That’s it.
    You will a result of something like this.

What Kind of Software Require This Combination of OpenAI Semantic Search with Neo4j Graph Database?

If you have these types of software, you definitely need to use this combination of OpenAI and Neo4j graph database to improve semantic search performance. There are certain examples where construction software are developed using OpenAI

Software CategoryExample
Knowledge Management Systems (KMS)
  • Slack
  • Notion
  • Asana
  • Google Drive
Customer Relationship Management (CRM)
  • Salesforce
  • Zoho CRM
  • Microsoft Dynamics 365
  • HubSpot
Enterprise Resource Planning (ERP)
  • SAP
  • Oracle
  • Microsoft Dynamics
  • NetSuite
Supply chain management and logistics systems
  • SAP Logistics
  • IBM Sterling
  • Oracle SCM
  • Infor SCM
Healthcare and life sciences research systems
  • Epic Systems
  • Cerner
  • Allscripts
  • MEDITECH

If you have any of such software solutions, we can help you integrate OpenAI semantic search technology with the Neo4j graph database. Schedule your free consultation below.

Moreover, if you are looking to explore more about the different blogs related to OpenAI technology, check the following section.

  1. Unique Features to Integrate into the Construction Software Using OpenAI
  2. Top 5 Use Cases of Using OpenAI Technology in Commercial Construction
  3. Reasons to Use OpenAI When Developing Construction Software

Want to Improve Search Performance in Your Software?

Let’s get in touch. We can help you. We have experience in improving the semantic search of enterprise-level clients.

FAQ About Using OpenAI to Improve Search Semantic

What are the benefits of using OpenAI semantic search with Neo4j?

Here are the benefits you get by using OpenAI semantic search with Neo4j.

  • Enhanced search accuracy to understand and interpret user queries
  • Improved user experience to make it easier for finding relevant information
  • Improved efficiency to quickly search and retrieve information from the backend
  • Scalability to handle large volumes of data for growing organizations
  • Enhanced data insights to gain deeper insights into your data and relationship in your graph

How do you get started with using OpenAI semantic search with the Neo4j database?

Here are the steps to get started with OpenAI semantic search with the Neo4j database.

  • Get familiar with OpenAI semantic search and Neo4j
  • Assess your data and use cases
  • Setup your environment
  • Integrate OpeAI semantic search with your Neo4j database
  • Testing and configuration for accurate results
  • Launch your OpenAI semantic search with your Neo4j database

Which types of queries can be performed with OpenAI semantic search and Neo4j?

Here are the multiple types of queries you can perform with OpenAI semantic search and Neo4j.

  • Node retrieval
  • Relationship retrieval
  • Graph traversal
  • Pattern matching
  • Cypher queries

Let’s Use OpenAI to Improve the Search Performance of Your Software Solution

With our experience in OpenAI models, APIs, and software development, we can help you in these two cases:

If you want to

  1. Improve the search scalability or improve the search accuracy in your existing software.
  2. Create an enterprise-level custom software solution with advanced technologies like OpenAI and Neo4j.

Let’s get in touch.