Spring / Spring AI interview questions
What is PgVector and how do you configure it as a VectorStore in Spring AI?
PgVector is an open-source PostgreSQL extension that adds a vector column type and approximate nearest-neighbour index operators to Postgres. Spring AI's PgVectorStore uses it to store document embeddings and run similarity searches directly inside your existing Postgres database — no separate vector database service required.
Setup requires three things: the pgvector extension enabled in Postgres, the Spring AI PgVector starter, and connection properties.
<!-- Dependency -->
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-pgvector-store-spring-boot-starter</artifactId>
</dependency># application.properties
spring.ai.vectorstore.pgvector.index-type=HNSW
spring.ai.vectorstore.pgvector.distance-type=COSINE_DISTANCE
spring.ai.vectorstore.pgvector.dimensions=1536 # must match your embedding model
spring.datasource.url=jdbc:postgresql://localhost:5432/mydbOn startup, Spring AI auto-creates the vector_store table with the correct schema if it does not exist (configurable). The index type is important for performance: HNSW (Hierarchical Navigable Small World) gives fast approximate search with slightly slower inserts; IVFFlat is cheaper to build but slower to search. For most production use cases HNSW is the better default.
The dimensions property must exactly match the output dimensions of your embedding model. OpenAI text-embedding-3-small is 1536, text-embedding-3-large is 3072, Ollama nomic-embed-text is 768. A mismatch causes a startup exception or runtime SQL error.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
