11import Foundation
22import OpenAIService
33
4- public final class RetrievalQAChain : Chain {
4+ public final class QAInformationRetrievalChain : Chain {
55 let vectorStore : VectorStore
66 let embedding : Embeddings
77
88 public struct Output {
9- public var answer : String
9+ public var information : String
1010 public var sourceDocuments : [ Document ]
1111 }
1212
@@ -26,7 +26,9 @@ public final class RetrievalQAChain: Chain {
2626 let documents = try await vectorStore. searchWithDistance (
2727 embeddings: embeddedQuestion,
2828 count: 5
29- )
29+ ) . filter { item in
30+ item. distance < 0.31
31+ }
3032
3133 callbackManagers. send ( CallbackEvents . RetrievalQADidExtractRelevantContent ( info: documents) )
3234
@@ -36,24 +38,21 @@ public final class RetrievalQAChain: Chain {
3638 callbackManagers: callbackManagers
3739 )
3840
39- return . init( answer : relevantInformation, sourceDocuments: documents. map ( \. document) )
41+ return . init( information : relevantInformation, sourceDocuments: documents. map ( \. document) )
4042 }
4143
4244 public func parseOutput( _ output: Output ) -> String {
43- return output. answer
45+ return output. information
4446 }
4547}
4648
4749public extension CallbackEvents {
4850 struct RetrievalQADidExtractRelevantContent : CallbackEvent {
4951 public let info : [ ( document: Document , distance: Float ) ]
5052 }
51-
53+
5254 var retrievalQADidExtractRelevantContent : RetrievalQADidExtractRelevantContent . Type {
5355 RetrievalQADidExtractRelevantContent . self
5456 }
5557}
5658
57-
58-
59-
0 commit comments