Coder Social home page Coder Social logo

springai-goodreads's Introduction

Spring AI application with Spring Data Neo4j

This is an example application using Spring AI, Spring Data Neo4j, Neo4j (utilizing both vector search and graph search capabilities), and Goodreads book data.

Data set

Data is maintained and pulled from a public data source. Load scripts and more information is available in this data set Github repository. An example of the data model is shown below.

goodreads data model

For this project, we are focusing on the Book and Review entities and the relationship between them.

Notes

There were a few "gotchas" I found as I built this application.

  1. Create a specific Neo4jVectorStore bean, even though the integration test in the guide shows a generic VectorStore one.

  2. Spring AI with Neo4j uses a default vector index name of spring-ai-document-index and default entity type of Document. You can customize these with the .withIndexName("<index-name>") and .withLabel("<label>") methods attached to the Neo4jVectorStore configuration.

  3. Spring AI requires property names of id and text to return in the list of Documents from the similaritySearch method (no matter what label is configured for the Neo4jVectorStore bean). If your properties are named something else, the Spring app cannot map them from the Neo4j node to the expected Document object. You can refactor the data in Neo4j to change the property names to id and text.

Running and testing this project

To run the application, you will need the following:

  • Neo4j database credentials. You can set these in the application.properties file or as environment variables on the machine.

  • OpenAI API key: they offer a free tier that works for this.

Once that’s set up, execute the application with ./mvnw spring-boot:run.

You can test a few different things. The /hello endpoint only sends the question to the LLM as a test. The /rag endpoint goes to Neo4j before forwarding the returned graph data to the LLM for formatting the response. The /llm endpoint only sends the prompt to the LLM, and the /vector only retrieves reviews from the vector search in Neo4j. Here are some ideas for values to test the /rag endpoint:

http ":8080/rag?searchPhrase=happy%20ending"

http ":8080/rag?searchPhrase=encouragement"

http ":8080/rag?searchPhrase=high%tech"

http ":8080/rag?searchPhrase=caffeine"

Note: The above commands are using the HTTPie command line tool, but you can use curl similarly.

Presentation

PDF versions of accompanying presentations are published to SpeakerDeck.

Resources

springai-goodreads's People

Contributors

jmhreif 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.