Skip to content

Semantic search API using Spring Boot and pgvector. Store text with embeddings and retrieve semantically similar results via cosine distance.

Notifications You must be signed in to change notification settings

apascualco/semantic-search

Repository files navigation

🚀 Semantic Search API

Spring Boot API for storing and querying semantically similar text using vector embeddings and cosine distance, powered by Ollama and pgvector.

📦 Requirements

  • Java 21+
  • Docker & Docker Compose
  • Ollama (local LLM inference)

🧠 1. Install Ollama and the Embedding Model

1.1 Install Ollama

1.2 Run the Embedding Model

  • ollama run nomic-embed-text

☑️ Ollama API will be available at http://localhost:11434

🐘 2. Start PostgreSQL with pgvector

2.1 Launch Database

docker-compose up -d

2.2 Postgres Details

  • Host: localhost
  • Port: 5432
  • User: search
  • Password: search
  • Database: search

2.3 SQL Setup

If the schema isn't auto-created, run this:

CREATE EXTENSION IF NOT EXISTS vector;

CREATE TABLE text (
    id UUID PRIMARY KEY,
    content TEXT,
    embedding vector(768)
);

CREATE INDEX idx_text_embedding_hnsw
ON text USING hnsw (embedding vector_cosine_ops);

⚙️ 3. Run the Application

3.1 Run with Gradle

./gradlew bootRun

3.2 Or build and run the jar

./gradlew build
java -jar build/libs/semantic-search-*.jar

3.3 Application URLs

📬 Example Endpoints

POST /text → Store a new text with its embedding

POST /search → Search for similar texts

About

Semantic search API using Spring Boot and pgvector. Store text with embeddings and retrieve semantically similar results via cosine distance.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages