Commit Graph

69 Commits

Author SHA1 Message Date
LangChain4j a1b733d96d bumped version to 0.32.0-SNAPSHOT 2024-05-24 16:25:13 +02:00
LangChain4j d9cb1e9b81
Release 0.31.0 (#1151) 2024-05-23 17:40:52 +02:00
LangChain4j 66c338c135 changed version to 0.31.0-SNAPSHOT 2024-04-29 11:21:00 +02:00
LangChain4j 1a340893ec
Release 0.30.0 (#945) 2024-04-16 18:21:01 +02:00
LangChain4j d1d9b45adc bumped to 0.30.0-SNAPSHOT 2024-04-08 17:36:52 +02:00
LangChain4j 45b58ac993
released 0.29.1 (#857) 2024-03-28 16:42:45 +01:00
LangChain4j d1e3cc1693
Release 0.29.0 (#830) 2024-03-26 11:54:43 +01:00
LangChain4j 91db3d354a bumped to 0.29.0-SNAPSHOT 2024-03-14 13:31:28 +01:00
LangChain4j 90fe3040b9
released 0.28.0 (#735) 2024-03-11 20:08:55 +01:00
LangChain4j 1acb7a607f
EmbeddingStore (Metadata) Filter API (#610)
## New EmbeddingStore (metadata) `Filter` API
Many embedding stores, such as
[Pinecone](https://docs.pinecone.io/docs/metadata-filtering) and
[Milvus](https://milvus.io/docs/boolean.md) support strict filtering
(think of an SQL "WHERE" clause) during similarity search.
So, if one has an embedding store with movies, for example, one could
search not only for the most semantically similar movies to the given
user query but also apply strict filtering by metadata fields like year,
genre, rating, etc. In this case, the similarity search will be
performed only on those movies that match the filter expression.

Since LangChain4j supports (and abstracts away) many embedding stores,
there needs to be an embedding-store-agnostic way for users to define
the filter expression.

This PR introduces a `Filter` interface, which can represent both simple
(e.g., `type = "documentation"`) and composite (e.g., `type in
("documentation", "tutorial") AND year > 2020`) filter expressions in an
embedding-store-agnostic manner.

`Filter` currently supports the following operations:

- Comparison:
  - `IsEqualTo`
  - `IsNotEqualTo`
  - `IsGreaterThan`
  - `IsGreaterThanOrEqualTo`
  - `IsLessThan`
  - `IsLessThanOrEqualTo`
  - `IsIn`
  - `IsNotIn`

- Logical:
  - `And`
  - `Not`
  - `Or`

These operations are supported by most embedding stores and serve as a
good starting point. However, the list of operations will expand over
time to include other operations (e.g., `Contains`) supported by
embedding stores.

Currently, the DSL looks like this:
```java
Filter onlyDocs = metadataKey("type").isEqualTo("documentation");

Filter docsAndTutorialsAfter2020 = metadataKey("type").isIn("documentation", "tutorial").and(metadataKey("year").isGreaterThan(2020));
// or
Filter docsAndTutorialsAfter2020 = and(
    metadataKey("type").isIn("documentation", "tutorial"),
    metadataKey("year").isGreaterThan(2020)
);
```

## Filter expression as a `String`
Filter expression can also be specified as a `String`. This might be
necessary, for example, if the filter expression is generated
dynamically by the application or by the LLM (as in [self
querying](https://python.langchain.com/docs/modules/data_connection/retrievers/self_query/)).

This PR introduces a `FilterParser` interface with a simple `Filter
parse(String)` API, allowing for future support of multiple syntaxes (if
this will be required).

For the out-of-the-box filter syntax, ANSI SQL's `WHERE` clause is
proposed as a suitable candidate for several reasons:
- SQL is well-known among Java developers
- There is extensive tooling available for SQL (e.g., parsers)
- LLMs are pretty good at generating valid SQL, as there are tons of SQL
queries on the internet, which are included in the LLM training
datasets. There are also specialized LLMs that are trained for
text-to-SQL task, such as [SQLCoder](https://huggingface.co/defog).

The downside is that SQL's `WHERE` clause might not support all
operations and data types that could be supported in the future by
various embedding stores. In such case, we could extend it to a superset
of ANSI SQL `WHERE` syntax and/or provide an option to express filters
in the native syntax of the store.

An out-of-the-box implementation of the SQL `FilterParser` is provided
as a `SqlFilterParser` in a separate module
`langchain4j-embedding-store-filter-parser-sql`, using
[JSqlParser](https://github.com/JSQLParser/JSqlParser) under the hood.

`SqlFilterParser` can parse SQL "SELECT" (or just "WHERE" clause)
statement into a `Filter` object:
- `SELECT * FROM fake_table WHERE userId = '123-456'` ->
`metadataKey("userId").isEqualTo("123-456")`
- `userId = '123-456'`  ->  `metadataKey("userId").isEqualTo("123-456")`

It can also resolve `CURDATE()` and
`CURRENT_DATE`/`CURRENT_TIME`/`CURRENT_TIMESTAMP`:
`SELECT * FROM fake_table WHERE year = EXTRACT(YEAR FROM CURRENT_DATE`
-> `metadataKey("year").isEqualTo(LocalDate.now().getYear())`

## Changes in `Metadata` API
Until now, `Metadata` supported only `String` values. This PR expands
the list of supported value types to `Integer`, `Long`, `Float` and
`Double`. In the future, more types may be added (if needed).
The method `String get(String key)` will be deprecated later in favor
of:
- `String getString(String key)`
- `Integer getInteger(String key)`
- `Long getLong(String key)`
- etc

New overloaded `put(key, value)` methods are introduced to support more
value types:
- `put(String key, int value)`
- `put(String key, long value)`
- etc

## Changes in `EmbeddingStore` API
New method `search` is added that will become the main entry point for
search in the future. All `findRelevant` methods will be deprecated
later.
New `search` method accepts `EmbeddingSearchRequest` and returns
`EmbeddingSearchResult`.
`EmbeddingSearchRequest` contains all search criteria (e.g.
`maxResults`, `minScore`), including new `Filter`.
`EmbeddingSearchResult` contains a list of `EmbeddingMatch`.
```java
EmbeddingSearchResult search(EmbeddingSearchRequest request);
```

## Changes in `EmbeddingStoreContentRetriever` API
`EmbeddingStoreContentRetriever` can now be configured with a static
`filter` as well as dynamic `dynamicMaxResults`, `dynamicMinScore` and
`dynamicFilter` in the builder:
```java
ContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder()
                .embeddingStore(embeddingStore)
                .embeddingModel(embeddingModel)
                ...
                .maxResults(3)
                // or
                .dynamicMaxResults(query -> 3) // You can define maxResults dynamically. The value could, for example, depend on the query or the user associated with the query.
                ...
                .minScore(0.3)
                // or
                .dynamicMinScore(query -> 0.3)
                ...
                .filter(metadataKey("userId").isEqualTo("123-456")) // Assuming your TextSegments contain Metadata with key "userId"
                // or
                .dynamicFilter(query -> metadataKey("userId").isEqualTo(query.metadata().chatMemoryId().toString()))
                ...
                .build();
```
So now you can define `maxResults`, `minScore` and `filter` both
statically and dynamically (they can depend on the query, user, etc.).
These values will be propagated to the underlying `EmbeddingStore`.

##
["Self-querying"](https://python.langchain.com/docs/modules/data_connection/retrievers/self_query/)
This PR also introduces `LanguageModelSqlFilterBuilder` in
`langchain4j-embedding-store-filter-parser-sql` module which can be used
with `EmbeddingStoreContentRetriever`'s `dynamicFilter` to automatically
build a `Filter` object from the `Query` using language model and
`SqlFilterParser`.

For example:
```java
TextSegment groundhogDay = TextSegment.from("Groundhog Day", new Metadata().put("genre", "comedy").put("year", 1993));
TextSegment forrestGump = TextSegment.from("Forrest Gump", new Metadata().put("genre", "drama").put("year", 1994));
TextSegment dieHard = TextSegment.from("Die Hard", new Metadata().put("genre", "action").put("year", 1998));

// describe metadata keys as if they were columns in the SQL table
TableDefinition tableDefinition = TableDefinition.builder()
                .name("movies")
                .addColumn("genre", "VARCHAR", "one of [comedy, drama, action]")
                .addColumn("year", "INT")
                .build();

LanguageModelSqlFilterBuilder sqlFilterBuilder = new LanguageModelSqlFilterBuilder(model, tableDefinition);

ContentRetriever contentRetriever = EmbeddingStoreContentRetriever.builder()
                .embeddingStore(embeddingStore)
                .embeddingModel(embeddingModel)
                .dynamicFilter(sqlFilterBuilder::build)
                .build();

String answer = assistant.answer("Recommend me a good drama from 90s"); // Forrest Gump
```

## Which embedding store integrations will support `Filter`?
In the long run, all (provided the embedding store itself supports it).
In the first iteration, I aim to add support to just a few:
- `InMemoryEmbeddingStore`
- Elasticsearch
- Milvus

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced filters for checking key's value existence in a collection
for improved data handling.
- **Enhancements**
- Updated `InMemoryEmbeddingStoreTest` to extend a different class for
improved testing coverage and added a new test method.
- **Refactor**
- Made minor formatting adjustments in the assertion block for better
readability.
- **Documentation**
  - Updated class hierarchy information for clarity.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-03-08 17:06:58 +01:00
LangChain4j 197b4af9d1 bumped version to 0.28.0-SNAPSHOT 2024-02-09 15:11:52 +01:00
LangChain4j c1462c087f
release 0.27.1 (#621) 2024-02-09 15:00:42 +01:00
LangChain4j ad2fd90f32 bumped version to 0.28.0-SNAPSHOT 2024-02-09 08:12:28 +01:00
LangChain4j a22d297104
Release 0.27.0 (#615) 2024-02-09 08:00:34 +01:00
Antonio Goncalves baac759766
Beautifying Maven output (#572)
Looking at the Maven output I thought it could benefit from a little
renaming. I just changed the `<name>` in the `pom.xml`, nothing more.
The output is like this at the moment:

![Screenshot 2024-01-30 at 16 26
53](https://github.com/langchain4j/langchain4j/assets/729277/940886d1-565e-416f-a58e-91f609fc0c00)

It could look like this if this PR is merged:

![Screenshot 2024-01-30 at 16 42
38](https://github.com/langchain4j/langchain4j/assets/729277/f8787af2-b869-4e95-90bd-72bce5622737)

Just a personal taste. Let me know if you like it or not (or want to
change it). If not, just discard it, it's fine ;o)
2024-01-30 16:54:54 +01:00
LangChain4j fca8ca48f7 bump version to 0.27.0-SNAPSHOT 2024-01-30 16:18:40 +01:00
LangChain4j 3958e01738
release 0.26.1 (#570) 2024-01-30 16:11:21 +01:00
LangChain4j 469699b944 bump version to 0.27.0-SNAPSHOT 2024-01-30 08:07:45 +01:00
LangChain4j a8ad9e48d9
Automate release (#562) 2024-01-30 07:20:20 +01:00
LangChain4j 7e5e82b7b2 updated to 0.26.0-SNAPSHOT 2023-12-22 18:08:19 +01:00
LangChain4j 2a5308b794 released 0.25.0 2023-12-22 18:02:04 +01:00
LangChain4j b51f5f99da
fixed pinecone client CVEs (#409) 2023-12-22 14:02:40 +01:00
shalk(xiao kun) 28b28825f4
fix pinecone QueryRequest usage, upgrade from 0.2.1 to 0.6.0 (#406)
when i test langchain4j-pinecone, the pinecone server respone error Info
```
 The 'queries' parameter has been deprecated.
```
ref to
[this](https://community.pinecone.io/t/invalid-argument-the-queries-parameter-has-been-deprecated-java/3719)
, then i fixed it.
2023-12-22 13:26:47 +01:00
LangChain4j e1dddb33a2
bumped version to 0.25.0-SNAPSHOT (#369) 2023-12-19 13:03:48 +01:00
LangChain4j ba7fabaa50
graal: cleanup (#297) 2023-11-19 12:59:24 +01:00
deep-learning-dynamo 6aed16ab81 reducing duplication of *EmbeddingStoreIT 2023-11-18 20:17:59 +01:00
deep-learning-dynamo 16f60dbef9 reducing duplication of *EmbeddingStoreIT 2023-11-18 16:23:29 +01:00
deep-learning-dynamo 21dfc8b317 released 0.24.0 2023-11-12 18:58:31 +01:00
deep-learning-dynamo f8871900be *EmbeddingStoreTest -> *EmbeddingStoreIT 2023-11-10 13:48:32 +01:00
Artur 7c12b39a8c
Allow using another metadata key than text_segment (#260) 2023-11-10 10:17:59 +01:00
deep-learning-dynamo f43cc8f4ca keep netty versions in sync 2023-10-17 21:16:18 +02:00
J b55f9e8a40
fix: remove high severity vulnerability in pinecone pom (#231)
Hi, this PR updates the pom of langchain4j-pinecone to remove a newly
discovered high severity [CVE-2023-44487
vulnerability](https://www.cve.org/CVERecord?id=CVE-2023-44487)
2023-10-17 21:11:29 +02:00
deep-learning-dynamo 315eab8641 released 0.23.0 2023-09-29 14:27:51 +02:00
deep-learning-dynamo ea57a4e584 added notes that metadata is not stored in milvus, pinecone and vespa 2023-09-28 23:48:21 +02:00
deep-learning-dynamo cd5f405b75 Pinecone: added test and licensing info 2023-09-28 18:19:09 +02:00
deep-learning-dynamo 4c8c69286d Pinecone: return matches from most relevant to less relevant 2023-09-28 12:41:25 +02:00
LangChain4j ad30b21805
Remove dynamic loading from Pinecone, Vespa and Weaviate (#187) 2023-09-21 12:08:51 +02:00
LangChain4j b804d03ca8
Fixed relevance score calculation (#164) 2023-09-07 19:19:20 +02:00
deep-learning-dynamo c1cc5be1c7 released 0.22.0 2023-08-29 19:21:56 +02:00
deep-learning-dynamo db1f236ed2 released 0.21.0 2023-08-19 15:57:39 +02:00
jiangsier-xyz d908f5158a
Integrate the Qwen series models via dashscope-sdk. (#99)
Qwen series models are provided by Alibaba Cloud. They are much better
in Asia languages then other LLMs.

DashScope is a model service platform. Qwen models are its primary
supported models. But it also supports other series like LLaMA2, Dolly,
ChatGLM, BiLLa(based on LLaMA)...These may be integrated sometime in the
future.
2023-08-18 20:49:50 +02:00
LangChain4j ba7fc4def6
Added an option to store ChatMemory anywhere (in memory, DB, etc) (#106)
- Added ChatMemoryStore and InMemoryChatMemoryStore
- Changed MessageWindowChatMemory and TokenWindowChatMemory to use
ChatMemoryStore
- Changed Supplier<ChatMemory> into ChatMemoryProvider
- Small improvements
2023-08-18 20:31:22 +02:00
deep-learning-dynamo d7b96ca9a6 released 0.20.0 2023-08-14 00:44:07 +02:00
deep-learning-dynamo 1541f214c1 released 0.19.0 2023-08-10 14:34:21 +02:00
LangChain4j f3757b8e18
[Snyk] Upgrade io.netty:netty-codec from 4.1.93.Final to 4.1.94.Final (#76)
authored-by: snyk-bot <snyk-bot@snyk.io>
2023-08-10 08:53:07 +02:00
LangChain4j 7497191bf9
Improvements (#79)
- did some refactorings
- added javadoc
- fixed NPE in PineconeEmbeddingStoreImpl when adding embedding by id
- PineconeEmbeddingStoreImpl now takes into account minScore and returns
score in EmbeddingMatch
- InMemoryEmbeddingStore now returns score instead of cosine similarity
2023-08-09 07:58:55 +02:00
deep-learning-dynamo 200bfe1fa3 updated langchain4j-pinecone name and description 2023-07-30 23:35:15 +02:00
deep-learning-dynamo d4fca658c1 released 0.18.0 2023-07-26 21:19:24 +02:00
LangChain4j 529ef6b647
Added in-process embedding models (#41)
- all-minilm-l6-v2
- all-minilm-l6-v2-q
- e5-small-v2
- e5-small-v2-q

The idea is to give users an option to embed documents/texts in the same
Java process without any external dependencies.
ONNX Runtime is used to run models inside JVM.
Each model resides in it's own maven module (inside the jar).
2023-07-23 19:05:13 +02:00
deep-learning-dynamo 1976560aeb released 0.16.0 2023-07-18 10:49:43 +02:00