Skip to content

Commit 214858b

Browse files
mkhecktzolov
authored andcommitted
Updated several vector db docs to fix errors and to expand on instructions, making it easier to follow and complete successfully: Azure AI Search, Neo4j, and Postgres/PGvector
1 parent dc86957 commit 214858b

File tree

3 files changed

+74
-41
lines changed

3 files changed

+74
-41
lines changed

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/azure.adoc

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -43,47 +43,47 @@ Add these dependencies to your project:
4343

4444
* OpenAI Embedding:
4545

46-
[source,xml]
47-
----
48-
<dependency>
49-
<groupId>org.springframework.ai</groupId>
50-
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
51-
<version>0.8.0-SNAPSHOT</version>
52-
</dependency>
53-
----
46+
[source,xml]
47+
----
48+
<dependency>
49+
<groupId>org.springframework.ai</groupId>
50+
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
51+
<version>0.8.0-SNAPSHOT</version>
52+
</dependency>
53+
----
5454

5555
* Or Azure AI Embedding:
5656

57-
[source,xml]
58-
----
59-
<dependency>
60-
<groupId>org.springframework.ai</groupId>
61-
<artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
62-
<version>0.8.0-SNAPSHOT</version>
63-
</dependency>
64-
----
57+
[source,xml]
58+
----
59+
<dependency>
60+
<groupId>org.springframework.ai</groupId>
61+
<artifactId>spring-ai-azure-openai-spring-boot-starter</artifactId>
62+
<version>0.8.0-SNAPSHOT</version>
63+
</dependency>
64+
----
6565

6666
* Or Local Sentence Transformers Embedding:
6767

68-
[source,xml]
69-
----
70-
<dependency>
71-
<groupId>org.springframework.ai</groupId>
72-
<artifactId>spring-ai-transformers-spring-boot-starter</artifactId>
73-
<version>0.8.0-SNAPSHOT</version>
74-
</dependency>
75-
----
68+
[source,xml]
69+
----
70+
<dependency>
71+
<groupId>org.springframework.ai</groupId>
72+
<artifactId>spring-ai-transformers-spring-boot-starter</artifactId>
73+
<version>0.8.0-SNAPSHOT</version>
74+
</dependency>
75+
----
7676

7777
2. Azure (AI Search) Vector Store
7878

79-
[source,xml]
80-
----
81-
<dependency>
82-
<groupId>org.springframework.ai</groupId>
83-
<artifactId>spring-ai-azure-vector-store</artifactId>
84-
<version>0.8.0-SNAPSHOT</version>
85-
</dependency>
86-
----
79+
[source,xml]
80+
----
81+
<dependency>
82+
<groupId>org.springframework.ai</groupId>
83+
<artifactId>spring-ai-azure-vector-store</artifactId>
84+
<version>0.8.0-SNAPSHOT</version>
85+
</dependency>
86+
----
8787

8888
== Sample Code
8989

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/neo4j.adoc

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ link:https://neo4j.com/docs/cypher-manual/current/indexes-for-vector-search/[Neo
1515
1. OpenAI Account: Create an account at link:https://platform.openai.com/signup[OpenAI Signup] and generate the token at link:https://platform.openai.com/account/api-keys[API Keys].
1616

1717
2. A running Neo4j (5.13+) instance
18-
a. link:https://hub.docker.com/_/neo4j[Docker] image _neo4j:5.13_
18+
a. link:https://hub.docker.com/_/neo4j[Docker] image _neo4j:5.15_
1919
b. link:https://neo4j.com/download/[Neo4j Desktop]
2020
c. link:https://neo4j.com/cloud/aura-free/[Neo4j Aura]
2121
d. link:https://neo4j.com/deployment-center/[Neo4j Server] instance
2222

2323
== Configuration
2424

25-
To connect to Neo4j and use the `Neo4jVectorStore`, you need to provide (e.g. via `application.properties`) configurations for your instance.
25+
To connect to Neo4j and use the `Neo4jVectorStore`, you need to provide (e.g. via `application.properties`, environment variables, etc.) configurations for your instance.
2626

2727
Additionally, you'll need to provide your OpenAI API Key. Set it as an environment variable like so:
2828

@@ -77,5 +77,38 @@ Add these dependencies to your project:
7777

7878
To configure `Neo4jVectorStore` in your application, you can use the following setup:
7979

80-
Add to `application.properties` (using your Neo4j credentials):
80+
Add to your environment (using your own Neo4j credentials and the appropriate access protocol+endpoint) the following properties either by updating and executing the following commands or creating a shell script to be run from your command prompt (Linux/Mac/WSL2):
8181

82+
[source,bash]
83+
----
84+
export SPRING_NEO4J_URI=<uri_for_your_neo4j_instance>
85+
export SPRING_NEO4J_AUTHENTICATION_USERNAME=<your_username>
86+
export SPRING_NEO4J_AUTHENTICATION_PASSWORD=<your_password>
87+
----
88+
89+
NOTE: If you choose to create a shell script for ease in future work, be sure to run it prior to starting your application by "sourcing" the file, i.e. `source <your_script_name>.sh`.
90+
91+
You'll need a `VectorStore` to store the embeddings. You can use the `Neo4jVectorStore` for this purpose, but first, you must create two beans the `Neo4jVectorStore` constructor requires. Here are examples of all of the beans you'll need:
92+
93+
[source,java]
94+
----
95+
@Bean
96+
public Driver driver() {
97+
return GraphDatabase.driver(System.getenv("SPRING_NEO4J_URI"),
98+
AuthTokens.basic(System.getenv("SPRING_NEO4J_AUTHENTICATION_USERNAME"),
99+
System.getenv("SPRING_NEO4J_AUTHENTICATION_PASSWORD")));
100+
}
101+
102+
@Bean
103+
public EmbeddingClient embeddingClient() {
104+
return new OpenAiEmbeddingClient(new OpenAiApi(System.getenv("SPRING_AI_OPENAI_API_KEY")));
105+
}
106+
107+
@Bean
108+
public VectorStore vectorStore(Driver driver, EmbeddingClient embeddingClient) {
109+
return new Neo4jVectorStore(driver, embeddingClient,
110+
Neo4jVectorStore.Neo4jVectorStoreConfig.defaultConfig());
111+
}
112+
----
113+
114+
The `Neo4jVectorStore` is now ready to be used in your application. You can use it to store embeddings and perform similarity searches.

spring-ai-docs/src/main/antora/modules/ROOT/pages/api/vectordbs/pgvector.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@ On startup, the `PgVectorStore` will attempt to install the required database ex
1818

1919
[sql]
2020
----
21-
CREATE EXTENSION IF NOT EXISTS vector
22-
CREATE EXTENSION IF NOT EXISTS hstore
23-
CREATE EXTENSION IF NOT EXISTS "uuid-ossp"
21+
CREATE EXTENSION IF NOT EXISTS vector;
22+
CREATE EXTENSION IF NOT EXISTS hstore;
23+
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
2424
2525
CREATE TABLE IF NOT EXISTS vector_store (
2626
id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
2727
content text,
2828
metadata json,
2929
embedding vector(1536)
30-
)
30+
);
3131
32-
CREATE INDEX ON vector_store USING HNSW (embedding vector_cosine_ops)
32+
CREATE INDEX ON vector_store USING HNSW (embedding vector_cosine_ops);
3333
----
3434

3535
== Configuration
@@ -111,7 +111,7 @@ Add to `application.yml` (using your DB credentials):
111111
----
112112
spring:
113113
datasource:
114-
url: jdbc:postgresql://localhost:5432/vector_store
114+
url: jdbc:postgresql://localhost:5432/postgres
115115
username: postgres
116116
password: postgres
117117
----

0 commit comments

Comments
 (0)