# pgvector **Repository Path**: ease-meta/pgvector ## Basic Information - **Project Name**: pgvector - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-04-21 - **Last Updated**: 2026-04-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SpringAI PgVector Integration with Ollama This project demonstrates how to integrate SpringAI with PgVector for vector database storage and use Ollama to connect to the local qwen3.5:27b model. ## Prerequisites 1. **PostgreSQL with PgVector extension** - Install PostgreSQL (version 14+ recommended) - Install PgVector extension: `CREATE EXTENSION vector;` - Create a database named `vector_db` 2. **Ollama** - Install Ollama from https://ollama.com/ - Pull the qwen3.5:27b model: `ollama pull qwen3.5:27b` - Start the Ollama service 3. **Java 17+** - Install JDK 17 or higher 4. **Maven** - Install Maven 3.6+ (for building the project) ## Project Structure ``` src/ ├── main/ │ ├── java/com/example/springai_pgvector/ │ │ ├── SpringaiPgvectorApplication.java # Main application class │ │ ├── config/VectorConfig.java # Configuration for vector store │ │ ├── controller/VectorController.java # REST API endpoints │ │ ├── entity/VectorEmbedding.java # Vector embedding entity │ │ ├── repository/VectorEmbeddingRepository.java # JPA repository │ │ └── service/VectorService.java # Business logic for vector operations │ └── resources/ │ └── application.properties # Application configuration └── test/ └── java/com/example/springai_pgvector/ └── SpringaiPgvectorApplicationTests.java # Test class ``` ## Configuration The application.properties file contains the following configuration: ```properties # PostgreSQL Configuration spring.datasource.url=jdbc:postgresql://localhost:5432/vector_db spring.datasource.username=postgres spring.datasource.password=postgres spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect # Ollama Configuration spring.ai.ollama.base-url=http://localhost:11434 spring.ai.ollama.chat.model=qwen3.5:27b spring.ai.ollama.embedding.model=qwen3.5:27b # PgVector Configuration spring.ai.vectorstore.pgvector.enabled=true spring.ai.vectorstore.pgvector.table-name=vector_embeddings spring.ai.vectorstore.pgvector.distance-type=cosine ``` ## API Endpoints ### Add Document - **Endpoint**: `POST /api/vector/add` - **Parameters**: - `content`: The text content to embed and store - `metadata` (optional): Additional metadata as key-value pairs - **Response**: Success message ### Search Similar Documents - **Endpoint**: `GET /api/vector/search` - **Parameters**: - `query`: The search query - `topK` (optional): Number of results to return (default: 5) - **Response**: List of similar documents with their content and metadata ### Clear All Documents - **Endpoint**: `DELETE /api/vector/clear` - **Response**: Success message ## How to Run 1. **Build the project**: ```bash mvn clean install ``` 2. **Run the application**: ```bash mvn spring-boot:run ``` 3. **Test the API**: - Add a document: `POST http://localhost:8080/api/vector/add?content=Hello world` - Search for similar documents: `GET http://localhost:8080/api/vector/search?query=Hi there` ## Dependencies - Spring Boot 4.0.5 - Spring AI 1.0.0-M1 - PostgreSQL Driver - PgVector Store - Ollama Client ## Notes - Ensure that PostgreSQL is running with the PgVector extension enabled - Ensure that Ollama is running and the qwen3.5:27b model is available - The application will automatically create the necessary table structure in the database - Vector embeddings are generated using the qwen3.5:27b model via Ollama