-
-
Save muyiwexy/631fbe15862215a55698a0e5be19f794 to your computer and use it in GitHub Desktop.
langchain_service_impl.dart(4)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LangchainServicesImpl extends LangchainService { | |
final Connection connection; | |
final OpenAIEmbeddings embeddings; | |
final OpenAI openAI; | |
LangchainServicesImpl({ | |
required this.connection, | |
required this.embeddings, | |
required this.openAI, | |
}); | |
// do something | |
// do something | |
// do something | |
// do something | |
// do something | |
// do something | |
@override | |
Future<void> storeDocumentData(Document doc, List<Document> chunks, | |
List<List<double>> embeddedDoc, String tableName) async { | |
debugPrint("Storing chunks and emedded vectors in the $tableName table"); | |
await connection.runTx((s) async { | |
for (int i = 0; i < chunks.length; i++) { | |
final txtPath = doc.metadata['source'] as String; | |
final chunk = chunks[i]; | |
final embeddingArray = embeddedDoc[i]; | |
await s.execute( | |
Sql.named( | |
'INSERT INTO $tableName (id, metadata, embedding) VALUES (@id, @metadata, @embedding)', | |
), | |
parameters: { | |
'id': '${txtPath}_$i', | |
'metadata': { | |
...chunk.metadata, | |
'loc': jsonEncode(chunk.metadata['loc']), | |
'pageContent': chunk.pageContent, | |
'txtPath': txtPath, | |
}, | |
'embedding': '$embeddingArray', | |
}, | |
); | |
} | |
}); | |
} | |
} | |
void debugPrint(String message) { | |
if (kDebugMode) { | |
print(message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment