Commit Graph

77 Commits

Author SHA1 Message Date
Mark Pollack
67a8896422 Next development version 2024-11-20 18:03:30 -05:00
Mark Pollack
33c05c399c Release version 1.0.0-M4 2024-11-20 18:02:47 -05:00
Christian Tzolov
018257a605 fix: Resolve javadoc and maven confiuration issues 2024-11-16 12:43:27 +01:00
Christian Tzolov
0ca91b2ed9 fix: Resolve various javadoc and checkstyle issues 2024-11-16 11:06:14 +01:00
Mark Pollack
a98af02f62 Minimize time to run main CI build action
- Add maven properties for all vector stores such as
skip.vectorstore.azure-cosmos-db to control IT test execution
- Chroma and PGVector IT tests are enabled by default
- Docker Compose and Testcontainers module ITs are skipped by default
- Add parallel job to run docker-compose and testcontainers ITs
2024-11-11 16:19:08 -05:00
Soby Chacko
66f58d2d70 Change default build setting to disable Checkstyle enforcement
- Disable project-wide Checkstyle checks to unblock development
- Add documentation for enabling Checkstyle locally
- Fix remaining checkstyle violations in current codebase

Fixes #1669
2024-11-05 10:43:38 -05:00
Thomas Vitale
cca430428e Support case with missing system text in VectorStoreChatMemoryAdvisor
The system text advise prompt is only joined with the value of the system text if it's non-null and non-empty.

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-11-03 11:54:45 +01:00
Soby Chacko
e72ab6ba25 Addressing more checkstyle violations
- Enable checkstyle on more modules and adressing violations
review
2024-10-31 01:04:41 -04:00
Sébastien Deleuze
081840eef2 Skip tests requiring OpenAI API key
Adds @EnabledIfEnvironmentVariable annotation to integration tests that
use OpenAI embeddings. Tests will be skipped if OPENAI_API_KEY is not set,
making the build process more reliable for contributors who don't have
access to OpenAI services.
2024-10-29 12:15:44 -04:00
Soby Chacko
8e758dbd00 Introduce checkstyle plugin
- Based on https://github.com/spring-io/spring-javaformat
- In this iteration, checkstyles are only enabled for spring-ai-core
2024-10-24 16:43:59 -04:00
Sébastien Deleuze
f21b8a42b5 Refine Jackson ObjectMapper handling
ObjectMapper instantiation is costly, so unless its usage
is one-shot, it is better to create a reusable instance
for upcoming usage.

Also, before this commit, serialization of most Kotlin
classes was not supported due to the lack of proper
Jackson KotlinModule detection.

This commit:
 - Avoids per invocation ObjectMapper instantiation when
   relevant
 - Automatically detects and enables well-known Jackson
   modules including the Kotlin one
 - Removes org.springframework.ai.vectorstore.JsonUtils
   which looks not needed anymore

More optimizations are possible like reusing more
ObjectMapper instances, but this could introduce more breaking
changes so this commit intends to be a good first step.

Kotlin tests will be provided in a follow-up commit.

Additional changes:
 - Update ModelOptionsUtils to use JacksonUtils.instantiateAvailableModules()
 - Add missing license headers
 - Add missing author Javadoc comments
2024-10-24 09:20:47 +02:00
Christian Tzolov
278a61fde4 Fix doc ref links 2024-10-21 10:24:28 +02:00
Mark Pollack
4c83fe8302 Guard against NPE in ZhiPu embedding model
- Update retry test to pass - needs investigation
2024-10-08 23:37:00 +02:00
Mark Pollack
4a892b5269 Release version 1.0.0-M3 2024-10-08 23:18:50 +02:00
Thomas Vitale
012f07c97b Optimize Testcontainers config for VectorStores
* Unify image definition for vector stores in vector-store modules

* Unify image definition for vector stores in spring-ai-testcontainers module

Signed-off-by: Thomas Vitale <ThomasVitale@users.noreply.github.com>
2024-10-06 19:18:05 +02:00
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
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
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
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
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
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
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
Francisco Javier Torres
867bd173e5 Set embeddings on added Document objects for Milvus and PgVector stores. 2024-07-05 16:37:38 -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
Christian Tzolov
476164b6e3 Move the vector expression converters from core to their projects 2024-06-15 20:24:29 +02:00
Christian Tzolov
1d479e3aab Minor PgVector ITs improvements 2024-06-15 17:49:21 +02:00
Mark Pollack
ac91302eed Next development version 2024-05-28 13:53:04 -04:00
Mark Pollack
0670575f3e Release version 1.0.0-M1 2024-05-28 13:49:11 -04:00
Josh Long
2d43e40024 Add property to initialize schema for vector stores
* Default is fale
* Update docs
2024-05-26 00:31:19 -04:00
Josh Long
fbfc87e814 Refactoring of ChatClient to add fluent API and introduce Model as dependent object
* Rename the ModelClient class hierarchy into Model:
  - Rename ModelClient into Model. Update all code and doc references.
  - Rename ChatClient to ChatModel. Update all ChatClient suffixes and chatClient fields and variables in code and doc.
  - Rename EmbeddingClient into EmbeddingModel. Update the XxxEmbeddingClient class and variable suffixes and embeddingClient variables and fields in code and docs.
  - Rename ImageClient into ImageModel.
  - Rename SpeechClient into SpeechModel.
  - Rename TranscriptionClient into TranscriptionModel.
  - Update all javadocs and antora pages. Update the related diagrams.

* Create fluent API in ChatClient interface that now includes streaming support
* Add OpenAI FunctionCallbackWrapper2IT auto-config tests.
* Add ChatClientTest mockito testing.
* Add ChatModel#getDefaultOptions(), and remove @FunctionalInterface

* ChatModel enums extend the new ModelDescription interface.
* Implement fromOptions copy method in every ChatOptions implementation.
* Extend ChatClient to use the model default options if not provided explicitly.

* Update readme to provide guidance on how to adapt to breaking changes.

Co-authored-by: Christian Tzolov <ctzolov@vmware.com>
Co-authored-by: Mark Pollack <mpollack@vmware.com>
2024-05-22 16:07:12 -04:00
Christian Tzolov
3475f17e98 Unify the vector store module and pom names
spring-ai-qdrant -> spring-ai-qdrant-store
 spring-ai-cassandra -> spring-ai-cassandra-store
 spring-ai-pinecone -> spring-ai-pinecone-store
 spring-ai-redis -> spring-ai-redis-store
 spring-ai-qdrant -> spring-ai-qdrant-store
 spring-ai-gemfire -> spring-ai-gemfire-store
 spring-ai-azure-vector-store-spring-boot-starter -> spring-ai-azure-store-spring-boot-starter
 spring-ai-redis-spring-boot-starter -> spring-ai-redis-store-spring-boot-starter
2024-05-17 17:05:09 +02:00
Josh Long
04d854cc49 make project names consistent 2024-05-17 15:31:58 +02:00
Josh Long
c5b7dd9c46 i ran the spring javaformat maven plugin to clean up any source code incompatabilities. 2024-05-17 15:31:57 +02:00
Josh Long
8c758617f3 moving to ApplicationListener<ApplicationReadyEvent> to avoid slowing down the application on startup. 2024-05-17 15:31:53 +02:00
Sagar Bhat
773b7bd3ca PgVectorStore: creating an index only if missing
- Resolve an issue where a new index keeps getting created during application start up.
 - Solution is is to create an index only if an index on the embedding column does not exist.
 - Add missing index name.
2024-04-26 19:03:45 +02:00
Christian Tzolov
0b04c8928a Update vector-stores README links 2024-04-09 20:55:39 +02:00
Christian Tzolov
8e0fbe49ee Remove the spring-boot-starter-jdbc dependency from PGVector project 2024-04-09 10:57:17 +02:00
Eddú Meléndez
8fa675b145 Update spring boot version to 3.2.4 2024-04-04 13:43:01 +02:00
Mark Pollack
4c617e16b4 Prepare next development iteration 2024-03-12 14:33:45 -04:00
Mark Pollack
490f3cd1cb Milestone Release 0.8.1 2024-03-12 14:28:28 -04:00
Mark Pollack
bcb559a82c add license header plugin and update all java files 2024-03-06 17:39:37 -05:00
Christian Tzolov
cbb59ce616 Improve readability of the PgVector Store code
Related to #461
2024-03-03 08:54:21 +01:00
Mark Pollack
8532cb7bcc Bump to 0.8.1-SNAPSHOT 2024-02-23 11:11:14 -05:00
Mark Pollack
bc5c4e2c4f add jdbc starter to pgvector starter 2024-02-22 15:48:58 -05:00