Giter Club home page Giter Club logo

neo4j-vector-cli's Introduction

Neo4j Vector Index CLI

This tool combines the Neo4j Vector search capabilities with embeddings from OpenAI.

Getting started

The code itself is working for the example below, but it is in a WIP state. You can create your own binaries by invoking ./mvnw package. For creating native images, it is required to run the build process with a Graal JVM.

Common usage

The most common workflow would be to create embeddings first and then query those embeddings with search phrases. You have to have an OpenAI API key to use this tool. The tool expects the OPENAI_API_KEY environment variable to be set with a working key.

Note

Please note that the --label parameter has to be set on the main command before invoking the subcommand.

Create Embedding

Example usage

> neo4j-vector-cli --label Game create-embedding --properties name,about,description

This command will create embeddings for all nodes labeled :Game and join its fields name, about, and description to be tokenized. After getting the results back, it will store those on the nodes' property embedding per default. This property is customizable, please have a look at the Configuration section.

Search for Embedding

Example usage

> neo4j-vector-cli --label Game search 'fun family strategy'
{records:[{__elementId__:"4:2..",__similarity__:0.8931642},{__elementId__:"4:1..",__similarity__:0.892818},...]}

The default output format might surprise at the first glance, but this output can be taken directly as input for Neo4j's Cypher Shell.

Output as Cypher Shell input

> cypher-shell 'UNWIND $records as record MATCH (g:Game)-[:DEVELOPED_BY]-(d) WHERE elementId(g) = record.__elementId__ RETURN g.name as game_name, g.metacritic_score as metacritic_score, d.name as developer, record.__similarity__ as similarity'"
Type " -P $(neo4j-vector-cli --label Game search 'fun family strategy')

This gives you the option to combine the vector search results with arbitrary Cypher statements for further processing.

If you are just interested in the results from the vector search themselves, use the --format console output.

> neo4j-vector-cli --label Game search 'family calm peaceful fun' --format console -p name
Labels                        Properties                                                                                                              Similarity
[Game]                        [name=Sheltered]                                                                                                        0.88821214
[Game]                        [name=Alba: A Wildlife Adventure]                                                                                       0.88753295
[Game]                        [name=Before We Leave]                                                                                                  0.88637364
[Game]                        [name=Shelter]                                                                                                          0.88603795
[Game]                        [name=Deep Sea Tycoon: Diver\'s Paradise]                                                                               0.88546705

neo4j-vector-cli in action

Configuration

You can create a property file named ~/.neo4j-vector-cli.properties containing the configuration:

neo4j-vector-cli.uri = neo4j://localhost:7687
neo4j-vector-cli.password = maybe_secure

All properties can be found by invoking the command neo4j-vector-cli:

Usage: neo4j-vector-cli [-v] [--embedding-property=<embeddingProperty>]
                        --label=<label> [--model=<model>]
                        [--password=<password>] [--uri=<uri>] [--user=<user>]
                        [COMMAND]
      --embedding-property=<embeddingProperty>
                        Property to be used for storing and searching the
                          embedding.
                        Defaults to 'embedding'.
      --label=<label>   Node label to be used for the operation.
      --model=<model>   Training model to be used.Defaults to
                          'text-embedding-ada-002'.
      --password=<password>
                        Neo4j password to be used.
      --uri=<uri>       Neo4j server URI to connect to.
                        Defaults to 'bolt://localhost:7687'.
      --user=<user>     Neo4j user to be used.
                        Defaults to 'neo4j'.
  -v, --verbose         Verbose logging, defaults to 'false'.
Commands:
  search            Search with any phrase in the embeddings.
  create-embedding  Create embedding

or its subcommands.

search

Usage: neo4j-vector-cli search [-f=<format>] [-l=<limit>] [-t=<threshold>]
                               [-p=property[,property...]]... <phrase>
Search with any phrase in the embeddings.
      <phrase>            The search phrase.
  -f, --format=<format>   Output format, can be either 'parameter' or 'console'.
                          Parameter output can be used e.g. as input for
                            cypher-shell's -p(arameter) option.
                          Defaults to 'parameter'.
  -l, --limit=<limit>     Result size for search and output.
  -p, --properties=property[,property...]
                          Node properties to include in the result.
  -t, --threshold=<threshold>
                          Cap of accepted lower bound similarity (0.0 - 1.0).

create-embedding

Usage: neo4j-vector-cli create-embedding -p=property[,property...] [-p=property
       [,property...]]...
Create embedding
  -p, --properties=property[,property...]
         Node properties to include during embedding creation.

neo4j-vector-cli's People

Contributors

meistermeier avatar

Stargazers

Ulan Sametov avatar Paul Horn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.