Skip to content

LikhithPalya/indexforge-search-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ” IndexForge Search

A semantic search service for the Animal Kingdom, powered by PostgreSQL + pgvector.

IndexForge Search serves natural-language similarity queries over animal documents. It converts user queries into embedding vectors and finds the most relevant animals using cosine similarity search.


πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚         User Query              β”‚
β”‚  "fast predators in Africa"     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      Query Embedding            β”‚
β”‚  Convert text β†’ vector (1536d)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Vector Similarity Search      β”‚
β”‚  pgvector cosine distance (<=>)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚        Rank Results             β”‚
β”‚  Order by similarity score      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                 β”‚
                 β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Return Animal Documents       β”‚
β”‚  { name, description, score }   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ What This Service Does

  • βœ… Serves semantic search requests over animal documents
  • βœ… Reads animal data from PostgreSQL (pgvector)
  • βœ… Returns ranked results with similarity scores
  • βœ… Provides animal CRUD read endpoints

🚫 What This Service Does NOT Do

  • ❌ Read CSV files or ingest data
  • ❌ Call Wikipedia or any external data source
  • ❌ Perform data ingestion or ETL
  • ❌ Generate embeddings for documents (handled externally)

PostgreSQL is the only source of truth.


πŸ› οΈ Tech Stack

Component Technology
Language Java 21
Framework Spring Boot 3.3
Database PostgreSQL 16
Vector Store pgvector
Migrations Flyway
Build Tool Maven
Code Gen Lombok
Container Docker Compose

πŸ“ Project Structure

src/main/java/com/indexforge/search/
β”œβ”€β”€ IndexForgeSearchApplication.java       # Entry point
β”œβ”€β”€ controller/
β”‚   β”œβ”€β”€ AnimalController.java              # GET /api/v1/animals, GET /api/v1/animals/{id}
β”‚   └── SearchController.java             # GET /api/v1/search?q=
β”œβ”€β”€ dto/
β”‚   β”œβ”€β”€ AnimalResponse.java               # Full animal details
β”‚   └── SearchResultResponse.java         # Search hit (id, name, description, score)
β”œβ”€β”€ entity/
β”‚   └── Animal.java                        # JPA entity with pgvector column
β”œβ”€β”€ repository/
β”‚   └── AnimalRepository.java             # JPA + native pgvector queries
β”œβ”€β”€ service/
β”‚   └── AnimalService.java                # Read-only animal operations
β”œβ”€β”€ search/
β”‚   β”œβ”€β”€ SemanticSearchService.java        # Orchestrates vector search
β”‚   └── QueryEmbeddingService.java        # Converts query β†’ embedding vector
β”œβ”€β”€ config/
β”‚   └── AppConfig.java                    # Spring beans configuration
└── exception/
    β”œβ”€β”€ AnimalNotFoundException.java
    └── GlobalExceptionHandler.java

πŸ—„οΈ Database Schema

CREATE TABLE animals (
    id                BIGSERIAL PRIMARY KEY,
    name              VARCHAR(255) NOT NULL,
    height            VARCHAR(100),
    weight            VARCHAR(100),
    color             VARCHAR(255),
    lifespan          VARCHAR(100),
    diet              VARCHAR(255),
    habitat           TEXT,
    predators         TEXT,
    average_speed     VARCHAR(100),
    countries_found   TEXT,
    description       TEXT,
    wikipedia_summary TEXT,
    search_document   TEXT,
    embedding_vector  vector(1536),
    created_at        TIMESTAMP NOT NULL DEFAULT NOW()
);

Indexes

Name Type Column Purpose
idx_animals_name B-tree name Fast name lookups
idx_animals_diet B-tree diet Filter by diet
idx_animals_habitat GIN habitat Full-text search
idx_animals_created_at B-tree created_at Time-based sorting
(future) HNSW embedding_vector ANN vector search

🌐 API Endpoints

List All Animals

GET /api/v1/animals

Response: 200 OK

[
  {
    "id": 1,
    "name": "Cheetah",
    "height": "70-90 cm",
    "weight": "21-72 kg",
    "color": "Tan with black spots",
    "lifespan": "10-12 years",
    "diet": "Carnivore",
    "habitat": "African savanna",
    "predators": "Lions, Hyenas",
    "averageSpeed": "112 km/h",
    "countriesFound": "Kenya, Tanzania, Namibia",
    "description": "The cheetah is the fastest land animal...",
    "wikipediaSummary": "...",
    "createdAt": "2026-06-13T12:00:00"
  }
]

Get Animal by ID

GET /api/v1/animals/{id}

Response: 200 OK β€” Same format as above (single object)

Error: 404 Not Found

{
  "timestamp": "2026-06-13T12:00:00",
  "status": 404,
  "error": "Not Found",
  "message": "Animal not found with id: 99"
}

Semantic Search

GET /api/v1/search?q=fast animals that hunt in packs

Response: 200 OK

[
  {
    "animalId": 42,
    "animalName": "African Wild Dog",
    "description": "The African wild dog is a highly social predator...",
    "similarityScore": 0.91
  },
  {
    "animalId": 7,
    "animalName": "Cheetah",
    "description": "The cheetah is the fastest land animal...",
    "similarityScore": 0.87
  }
]

πŸš€ Getting Started

Prerequisites

  • Java 21
  • Docker & Docker Compose
  • Maven

Ru

n

# 1. Start PostgreSQL with pgvector
docker-compose up -d

# 2. Build the project
mvn clean install -DskipTests

# 3. Run the application
mvn spring-boot:run

The service starts on http://localhost:8080.

Verify

# Health check
curl http://localhost:8080/api/v1/animals

# Search (returns empty until implementation is complete)
curl "http://localhost:8080/api/v1/search?q=large%20herbivores"

🧩 Implementation Status

Component Status
Animal entity + migration βœ… Done
Animal read endpoints βœ… Done
Search endpoint (skeleton) βœ… Done
QueryEmbeddingService πŸ”² TODO
SemanticSearchService logic πŸ”² TODO
HNSW vector index πŸ”² TODO
Result pagination πŸ”² TODO
Similarity threshold πŸ”² TODO

πŸ“ Design Principles

  1. Read-only β€” This service only reads from PostgreSQL. Data population happens externally.
  2. Constructor injection β€” All dependencies injected via @RequiredArgsConstructor.
  3. Clean layering β€” Controller β†’ Service β†’ Repository. No business logic in controllers.
  4. DTO separation β€” API responses decoupled from JPA entities.
  5. Fail-fast β€” Unimplemented features throw UnsupportedOperationException with clear messages.
  6. Database-first β€” Schema managed by Flyway migrations.

πŸ“„ License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages