3
3
import com .datastax .astra .client .Database ;
4
4
import com .datastax .astra .client .model .CollectionOptions ;
5
5
import com .datastax .astra .client .model .SimilarityMetric ;
6
+ import com .datastax .astra .langchain4j .Assistant ;
6
7
import com .datastax .astra .langchain4j .AstraDBTestSupport ;
8
+ import com .datastax .astra .langchain4j .rag .AstraVectorizeContentRetriever ;
7
9
import com .datastax .astra .langchain4j .rag .AstraVectorizeIngestor ;
8
10
import com .datastax .astra .langchain4j .store .embedding .AstraDbEmbeddingStore ;
9
11
import com .datastax .astra .langchain4j .store .embedding .EmbeddingSearchRequestAstra ;
12
14
import dev .langchain4j .data .document .parser .TextDocumentParser ;
13
15
import dev .langchain4j .data .document .splitter .DocumentSplitters ;
14
16
import dev .langchain4j .data .segment .TextSegment ;
17
+ import dev .langchain4j .model .openai .OpenAiChatModelName ;
18
+ import dev .langchain4j .model .openai .OpenAiEmbeddingModelName ;
19
+ import dev .langchain4j .rag .DefaultRetrievalAugmentor ;
20
+ import dev .langchain4j .rag .RetrievalAugmentor ;
21
+ import dev .langchain4j .rag .content .retriever .ContentRetriever ;
22
+ import dev .langchain4j .rag .content .retriever .EmbeddingStoreContentRetriever ;
23
+ import dev .langchain4j .service .AiServices ;
15
24
import dev .langchain4j .store .embedding .EmbeddingMatch ;
16
25
import lombok .extern .slf4j .Slf4j ;
17
26
import org .junit .jupiter .api .BeforeAll ;
@@ -81,6 +90,23 @@ public void should_ingest_documents() {
81
90
82
91
@ Test
83
92
@ Order (2 )
93
+ public void should_search_with_content_retriever () {
94
+ AstraVectorizeContentRetriever contentRetriever = AstraVectorizeContentRetriever .builder ()
95
+ .embeddingStore (embeddingStoreVectorizeNVidia )
96
+ .maxResults (2 )
97
+ .minScore (0.5 )
98
+ .build ();
99
+ // configuring it to use the components we've created above.
100
+ Assistant ai = AiServices .builder (Assistant .class )
101
+ .contentRetriever (contentRetriever )
102
+ .chatLanguageModel (AstraDBTestSupport .createOpenAIChatLanguageModel (OpenAiChatModelName .GPT_4_O ))
103
+ .build ();
104
+ String response = ai .answer ("Who is Johnny?" );
105
+ System .out .println (response );
106
+ }
107
+
108
+ @ Test
109
+ @ Order (3 )
84
110
public void should_search_results () {
85
111
String question = "Who is Johnny?" ;
86
112
@@ -107,4 +133,14 @@ public void should_search_results() {
107
133
108
134
System .out .println (ragContext );
109
135
}
136
+
137
+ @ Test
138
+ @ Order (4 )
139
+ public void should_search_withResultAggregator () {
140
+ String question = "Who is Johnny?" ;
141
+ // Our guy for advanced RAG
142
+ RetrievalAugmentor retrievalAugmentor = DefaultRetrievalAugmentor .builder ()
143
+ .contentRetriever (AstraVectorizeContentRetriever .from (embeddingStoreVectorizeNVidia ))
144
+ .build ();
145
+ }
110
146
}
0 commit comments