Commit Graph

240 Commits

Author SHA1 Message Date
Thomas Vitale
50e11e3f46 Improve optional values handling in vector store observations
Vector store observations support several key-value pairs, coming from the Spring AI abstractions. Currently, whenever a value is not available (either because not configured by the user or not supported by the vector store provider), span/metrics attributes are generated anyway with value none.

That causes several issues, including an unneeded increase in time series, challenges in alerting/monitoring (especially for integer/double attributes that suddenly are populated with a string), and non-compliance with the OpenTelemetry Semantic Conventions (according to which, attributes should be excluded altogether if there's no value).

This pull request changes the conventions for vector store observations to exclude the generation of span/metrics attributes for optional values which don't have any value.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 15:36:18 +02:00
dafriz
439934b0f6 Set redis query limit to match requested topK used in KNN search 2024-10-03 16:34:22 -04:00
Eddú Meléndez
e58341a447 Use MongoDBAtlasLocalContainer from Testcontainers 1.20.2
Testcontainers 1.20.2 offers `MongoDBAtlasLocalContainer`. Previous
image used during tests was pulling images in every execution. The
new image is cached locally and can be executed offline.
2024-10-03 12:23:29 -04:00
Christian Tzolov
6fc76b7f9b Refactor advisor architecture in Spring AI
This commit introduces a major overhaul of the advisor system in Spring AI,
improving modularity, type safety, and consistency

Core Changes:
- Replace RequestAdvisor and ResponseAdvisor with CallAroundAdvisor and StreamAroundAdvisor
- Introduce AdvisedRequest and AdvisedResponse classes for better encapsulation
- Deprecate RequestResponseAdvisor in favor of new advisor types
- Remove AdvisorObservableHelper class

Advisor Implementation Updates:
- Update AbstractChatMemoryAdvisor, MessageChatMemoryAdvisor, PromptChatMemoryAdvisor,
QuestionAnswerAdvisor, SafeGuardAroundAdvisor, SimpleLoggerAdvisor, and
VectorStoreChatMemoryAdvisor to implement new advisor interfaces
- Remove CacheAroundAdvisor (functionality likely moved elsewhere)
- Make CallAroundAdvisor and StreamAroundAdvisor extend Ordered interface

Client and Chain Management:
- Modify DefaultChatClient to use new advisor chain approach
- Refactor DefaultAroundAdvisorChain for better ordering and observation
- Implement builder pattern for advisor chain construction in DefaultChatClient
- Separate call and stream advisors in DefaultAroundAdvisorChain

Observation and Context Handling:
- Update observation conventions and context handling in advisors
- Add order field to AdvisorObservationContext
- Modify DefaultAdvisorObservationConvention to include order in high cardinality key values

Testing and Integration:
- Refactor ChatClientAdvisorTests and add new AdvisorsTests
- Update integration tests to reflect new advisor structure
- Enhance AdvisorsTests to verify correct advisor execution order

New Features:
- Generalize the Protect From Blocking functionality across all advisors
- Add (experimental) Re2 advisor to enhance reasoning capabilities of LLMs
- Add disabled Re2 test in OpenAiChatClientIT

Documentation:
- Add Advisors documentation
- Enhance advisors documentation with order explanation and Re2 example

Advisor Ordering:
- Introduce Advisor constants for precedence ordering
- Update AbstractChatMemoryAdvisor to use new precedence constant
- Improve advisor ordering and management in DefaultAroundAdvisorChain.Builder
- Remove redundant reordering logic from DefaultAroundAdvisorChain

These changes aim to provide a more flexible and powerful advisor system,
allowing for easier implementation of complex AI-driven interactions

Co-authored-by: Dariusz Jędrzejczyk <dariusz.jedrzejczyk@broadcom.com>
2024-10-01 15:08:21 -04:00
Ricken Bazolo
835450761e handle http client error exception on getCollection method 2024-09-24 17:04:43 -04:00
Soby Chacko
202148d45b Prevent timeouts with configurable batching for PgVectorStore inserts
Resolves https://github.com/spring-projects/spring-ai/issues/1199

- Implement configurable maxDocumentBatchSize to prevent insert timeouts
  when adding large numbers of documents
- Update PgVectorStore to process document inserts in controlled batches
- Add maxDocumentBatchSize property to PgVectorStoreProperties
- Update PgVectorStoreAutoConfiguration to use the new batching property
- Add tests to verify batching behavior and performance

This change addresses the issue of PgVectorStore inserts timing out due to
large document volumes. By introducing configurable batching, users can now
control the insert process to avoid timeouts while maintaining performance
and reducing memory overhead for large-scale document additions.
2024-09-24 16:56:16 -04:00
Soby Chacko
66455b9ec5 Add batching strategy to more vector stores
Apply batching when adding Documents to the following vector stores:

- Azure vector store
- Cassandra
- MongoDB Atlas
- OpenSearch
- Oracle
- Pinecone

 This improves efficiency by processing multiple Documents at once instead of individually, reducing the overhead for each operation.

Related to #1261
2024-09-16 23:23:51 -04:00
Laura Trotta
5a3521330f adding version to header, fix 2024-09-12 18:47:56 +02:00
Laura Trotta
67c55cbcbe Added Elasticsearch Vector Store Unit Test (#1339)
* add and delete unit test
* format
2024-09-10 11:39:46 -04:00
Soby Chacko
15fdd05fac Add batching for more vector stores
Apply batching when adding Documents to the following vector stores:

- Chroma
- ElasticSearch
- Neo4j
- Qdrant
- Redis
- Typesense
- Weaviate

This improves efficiency by processing multiple Documents at once instead of individually, reducing the overhead for each operation.

Related to #1261
2024-09-09 15:28:22 -04:00
Laura Trotta
4f62ac1cee GH-1316: Elasticsearch vector store - Wrong error reported fix
Fixes: https://github.com/spring-projects/spring-ai/issues/1316

* Handling missing index case
* Docs update
* User header for observability
* Same exception management for delete
2024-09-09 11:58:29 -04:00
Soby Chacko
53721c642b Fix PgVectorStoreWithChatMemoryAdvisorIT from batching changes 2024-09-05 11:26:38 -04:00
fk
2c1f36c725 Fix problem with VectorStoreChatMemoryAdvisor using pgvector
- add integration test
2024-09-05 15:37:59 +02:00
Soby Chacko
087de16cfc Add batching strategy for embedding documents in PgVectorStore
- Precompute all embeddings using a BatchingStrategy before inserting into the vector store

This optimization improves efficiency when adding multiple documents

Related to #1261
2024-09-04 17:23:39 -04:00
Mark Pollack
e1884d1d92 Next development version 2024-08-23 18:47:37 -04:00
Mark Pollack
43ad2bdb97 Release version 1.0.0-M2 2024-08-23 18:46:58 -04:00
Josh Long
9dbb39ac4a pincecone vector aot hints 2024-08-23 00:26:50 -07:00
Soby Chacko
d752b3d8d7 Gemfire vector store cleanup
- Based on the pattern established in other vector store support implementations,
  added a builder class as an inner class of the GemfireVectorStoreConfig class which
  is also moved as an inner class to GemfireVectorStore.

Based on the original PR: https://github.com/spring-projects/spring-ai/pull/1168
2024-08-22 11:34:54 -04:00
Thomas Vitale
036093a42b Enhance vector store observability support
* Consolidate usage of “db.collection.name” attribute to track table name, collection name, index name, document name, or whatever concept a vector database uses to store data. Removed “db.index” that was use sometimes instead of “db.collection.name”. This usage is in line with the OpenTelemetry Semantic Conventions.
* Configure query response content to be included as a “span event” instead of a “span attribute” if the backend system supports that, similar to how we do for the model observations.
* Structure vector store observation attributes in dedicated enums, including one for the Spring AI Kinds to avoid hard-coding the same value in a lot of places. This follows the OpenTelemetry Semantic Conventions as much as possible. Also, adopt Spring usual non-null-by-default strategy as much as possible.
* Align vector store conventions to the chat model ones, and follow alphabetical order for values. This is particularly useful for the convention classes, for which the Micrometer performance of exporting telemetry data improves when key values are added already sorted to the context.
* Fix flaky test in Mistral AI.
* Improve Qdrant integration tests.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-08-22 09:38:59 +02:00
Soby Chacko
f0771f0770 Fixing MongoDB vector store support test failures
Remove the requirement of MongoDB vector store auto-configuration only after `MongoDataAutoConfiguration`.
This enables the `MongoDBAtlasVectorStoreAutoConfiguration` to properly provide custom Mongo conversions.

In `MongoDBAtlasVectorStoreIT` and `MongoDbVectorStoreObservationIT` tests, properly provision the `MongoTemplate`
with custom conversions as these tests are not relying on auto-configuration.
2024-08-21 07:10:54 +02:00
Soby Chacko
949f1ed4e8 Add Batching strategy for embedding documents
- When embedding documents, allow batching the documents using some criteria.
 - `BatchingStrategy` interface with a `TokenCountBatchingStrategy` implementation that uses
   the openai max input token size of 8191 as the default.
 - Add a default method in EmbeddingModel to embed document using this new batching strategy.
 - Change `MilvusVectorStore` to make use of this new batching API.
 - Adding unit tests for `TokenCountBatchingStrategy`.
 - Adding openai integration test to call the embed API that uses batching.

Resolves https://github.com/spring-projects/spring-ai/issues/1214

Other vector stores will be updated seperately
2024-08-20 14:08:06 -04:00
Christian Tzolov
7afc2b56a1 Disable MonogDB ITs due to #698 2024-08-20 16:19:25 +02:00
Christian Tzolov
e881fefc39 Add spring-ai-test to MongoDB pom 2024-08-20 13:41:21 +02:00
Christian Tzolov
4cc9a9ce4a Harden the WeaviateContainer initialization to prevent IT instability 2024-08-20 10:54:43 +02:00
Christian Tzolov
1465310cf0 Another OracleVectorStoreObservationIT test assertion fix 2024-08-20 10:09:17 +02:00
Christian Tzolov
a3f44872ee Fix OracleVectorStoreObservationIT bug 2024-08-20 09:27:08 +02:00
Christian Tzolov
93fa2bf45a Add observability support to existing vector stores
Add observability support to:
 - Cassandra
 - Chroma
 - Elasticsearch
 - Milvus
 - Neo4j
 - OpenSearch
 - Qdrant
 - Redis
 - Typesense
 - Weaviate
 - Pinecone
 - Oracle
 - Gemifire
 - MongoDB
 - HanaDB

 Add autoconfiguration obsrvability for the above vector stores.
 Add integration tests for all vector stores.
2024-08-20 01:37:45 -04:00
Muthukumaran Navaneethakrishnan
6bd059a8b7 Fix IN/NOT IN filters for PgVector JSON queries
PgVectorFilterExpressionConverter was generating incorrect SQL for
IN and NOT IN filters with PostgreSQL JSON data types. This caused
BadSqlGrammarException errors when executing queries.

This change modifies the converter to generate correct SQL syntax
for these operations, ensuring compatibility with PostgreSQL's JSON
handling capabilities.

Why:
- Improves query reliability for PgVector stores
- Enables more complex filtering operations on JSON data
- Eliminates unexpected errors in query execution

Fixes #1179
2024-08-16 11:21:37 -04:00
Christian Tzolov
bc3f9acb86 Add observability support to VectorStore
Implementation:
- Introduce AbstractObservationVectorStore with instrumentation for add, delete, and similaritySearch methods
- Create VectorStoreObservationContext to capture operation details
- Implement DefaultVectorStoreObservationConvention for naming and tagging
- Add VectorStoreObservationDocumentation for defining observation keys
- Create VectorStoreObservationAutoConfiguration for auto-configuring observations
- Add VectorStoreObservationProperties to control optional observation content filters
- Update VectorStore interface with getName() method
- Modify PgVectorStore and SimpleVectorStore to extend AbstractObservationVectorStore
- Add vector_store Spring AI kind

Filters:
- Implement VectorStoreQueryResponseObservationFilter
- Add VectorStoreDeleteRequestContentObservationFilter and VectorStoreAddRequestContentObservationFilter

Enhancements:
- Update PgVectorStoreAutoConfiguration to support observations
- Add observation support to PgVectorStore's Builder
- Add VectorStoreObservationContext.Operation enum with ADD, DELETE, and QUERY options

Tests:
- Add tests for VectorStore context, convention, and filters
- Add VectorStoreObservationAutoConfiguration tests
- Add PgVectorObservationIT

Resolves #1205
2024-08-16 10:33:50 -04:00
Soby Chacko
a051978600 Fixing float[] type embedding on MongoDBAtlas vector store 2024-08-14 18:58:07 -04:00
Christian Tzolov
d538e00643 Replace the Embedding format from List<Double> to float[]
- Adjust all affected classes including the Document.
 - Update docs.

Related to #405
2024-08-13 11:53:08 -04:00
Eddú Meléndez
80007d4d6c Update testcontainers version to 1.20.1
Weaviate module contains the wait strategy.
2024-08-07 09:25:58 +02:00
Ross Lawley
04191a77e0 Updated MongoDBAtlasVectorStore to use org.bson.Documents (#1026)
org.bson.Documents have been the preferred document structure
since the 3.0 release of the mongo-java-driver
2024-07-24 17:03:42 -04:00
dongfeng3692
fbdfd8557b Remove flush operations to prevent excessive segment creation in Milvus (#1104) 2024-07-24 16:50:03 -04:00
Soby Chacko
50d34b8a48 BREAKING CHANGE - Change vector store initialize-schema to false
* Change default schema initialization of vector stores from `true` to `false.`
  Users need to explicitly opt-in for schema initialization by setting the
  `initialize-schema` property on the corresponding vector store.
* Update integration tests
* Update docs

Fixes #907
2024-07-18 14:28:00 -04:00
Michael Simons
41d2cb5827 Upgrade to latest version of Cypher-DSL.
Also use the bom, so if anyone combines it with Spring Data, things settle at some common version.
2024-07-18 15:04:49 +02:00
Eddú Meléndez
0a07f65d6a Use RedisAutoConfiguration in RedisVectorStoreAutoConfiguration
Currently, `RedisVectorStoreAutoConfiguration` creates its own
configuration to connect with Redis. This commit reuse
`RedisAutoConfiguration` from spring boot project. It's limited
to Jedis.
2024-07-18 14:24:10 +02:00
mck
4aacab020b Implement CassandraChatMemory
- provides a flexible schema, can be combined with a vector store, and supports time-to-live rows.
 - fix initialize-schema docs and so that it actually works.
 - move CommonVectorStoreProperties to .vectorstore. package
 - add CassandraAutoConfiguration to the AutoConfiguration.imports
2024-07-17 11:42:09 +02:00
Eddú Meléndez
0a42bf01f3 Fix assertions 2024-07-17 11:01:37 +02:00
Francisco Javier Torres
867bd173e5 Set embeddings on added Document objects for Milvus and PgVector stores. 2024-07-05 16:37:38 -04:00
jiwoo
6931148377 Fix MilvusVectorStore max allowed dimension size to 32768 2024-07-05 16:32:59 -04:00
Ross Lawley
24da2efc86 Fix IndexAlreadyExists exception for spring-ai-mongodb-atlas-store
In testing the docker mongodb/atlas container doesn't throw an exception when
calling `mongoTemplate.executeCommand({"createSearchIndexes": ...});`. However,
when using the Atlas service it does and throws a `IndexAlreadyExists` exception.

Added error handling for error code 68 or error code name `IndexAlreadyExists`.
See: https://www.mongodb.com/docs/manual/reference/error-codes/

Fixes #910
2024-07-05 14:38:38 -04:00
Christian Tzolov
c09286eedf Fix javadoc formatting 2024-06-28 11:31:57 +02:00
dongfeng3692
df52c9fbb5 Minor javadoc improvements 2024-06-28 11:20:07 +02:00
Mark Pollack
a1c4a29073 AzureVectorStore Fix - when not initializing schema, create searchClient from index name 2024-06-26 19:22:53 -04:00
Eddú Meléndez
feecca77c3 Use Weaviate's readiness endpoint
Currently, Testcontainers Weaviate implementation relies on port availability.
This commit switch to Weaviate's readiness endpoint.
2024-06-24 17:48:04 +02:00
Mark Pollack
84737ecc01 update some javadoc warnings 2024-06-21 16:29:15 -04:00
Muthukumaran Navaneethakrishnan
f0ca61252b Add support for customizable PgVectorStore schema, table, and index names (#747)
This change allows users to specify custom names, facilitating management of multiple vector databases within a single database instance.

 Key changes:
 - Implement configurable schema, table, and index names for PgVectorStore
 - Add properties to set custom schema and table names
 - Introduce optional schema/table & field validation for custom configurations
 - Include additional tests for new configurations and existing deployments

 Additional improvements:
 - Rename properties to schemaName, tableName, and schemaValidation
 - Update pgvector documentation with new properties
 - Add schema/table name tests to PgVectorStoreAutoConfigurationIT and PgVectorStorePropertiesTests
 - Create standalone PgVectorSchemaValidator class for schema/table validation
 - Add missing 'CREATE SCHEMA IF NOT EXISTS' when initializeSchema=true
 - Remove redundant code and classes

 Resolves #747

Co-authored-by: Christian Tzolov <ctzolov@vmware.com>
2024-06-21 11:02:22 +02:00
geetrawat
067a33dbe2 Improved GemFire support
- Adds spring boot auto-configuration support for GemFireVectorStore
- Adds integration test GemFireVectorStoreAutoConfigurationIT
- Includes gemfire-testcontainers in integration tests
- Adds unit test GemFireVectorStorePropertiesTests
- Refactors GemFireVectorStore.java extracting GemFireVectorStoreConfig.java
- Renames spring-ai-gemfire to spring-ai-gemfire-store
- Adds GemFireConnectionDetails
- Adds GemFireVectorStoreProperties with default values
- Remove gemfire-release-repo maven repository

Co-authored-by: Louis Jacome <louis.jacome@broadcom.com>
Co-authored-by: Jason Huyn <jason.huynh@broadcom.com>
2024-06-20 17:17:13 -04:00
Eddú Meléndez
5844f9bf39 Polish Qdrant tests
Use helper methods provided by Testcontainers.
2024-06-20 07:16:03 +02:00