Posts

Building a Retrieval-Augmented Generation (RAG) Application with Ollama 3.2 and Spring Boot

Building a RAG Application with Ollama 3.2 and Spring Boot This blog post demonstrates how to build a Retrieval-Augmented Generation (RAG) application using Ollama 3.2 for large language models (LLMs) and Spring Boot for creating REST APIs. RAG combines information retrieval with LLMs to provide more accurate and contextually relevant answers. We'll leverage Docker Desktop for containerization and pgvector for vector storage. Project Setup We'll use Spring Boot version 3.3.7 for this project. Here's a breakdown of the key components and configurations: 1. Dependencies (Gradle): dependencies { implementation 'org.springframework.boot:spring-boot-starter-jdbc' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'com.fasterxml.jackson.module:jackson-module-kotlin' implementation 'org.springframework.ai:spring-ai-ollama-spring-boot-starter' ...

Securing Microservices with JWT Authentication and Data Encryption

Securing Microservices with JWT Authentication and Data Encryption Securing Microservices with JWT Authentication and Data Encryption In modern microservices architectures, securing communication and data integrity are paramount. This article explores how JWT (JSON Web Token) authentication and data encryption can bolster security, ensuring that data exchanges between services remain confidential and trusted. What is JWT Authentication? JWT is a compact, URL-safe token format that securely transmits information between parties as a JSON object. It is widely used in microservices for its simplicity and efficiency. Parts of a JWT Token A JSON Web Token (JWT) consists of three parts, separated by periods ( . ): Header: Specifies the token type ( JWT ) and signing algorithm (e.g., HS256 or RS256 ). Example:...

Android aar deployment in Maven - 2022

Introduction If you are working on android library project, you might be wondering how to publish it on Maven like this . Earlier it was done using Android studio plugin maven , but with gradle v 7.0+ it does not work. Now we have to use maven-publish . This post gives you more insights of this procedure. Generally, there are two types of repositories: local and remote. A local repository is the repository Maven creates on the computer it is building on. It is usually located under the $HOME/.m2/repository directory. Remote repository is located on maven server. When any user wants to use our library, they will enter groupId and version of library they want to use. We will create and deploy a new android aar artifact on maven. The process can be summarized as 1. Create Account and repository on Nexus sonatype 2. Configure gradle to create, sign and upload aar file to sonatype. 3. Let sonatype verify the artifacts as per maven requirement (Close ope...

Flutter: Making dashed line matching width of screen

Image
 How can we make dashed line in flutter? Dart does not have support for this yet. We need to make custom widget for showing dashed line. Code is given below. class LinePainter extends CustomPainter { @override void paint ( Canvas canvas, Size size) { var max = size. width ; debugPrint ( "LinePainter max= $ max " ); var dashWidth = 5.0 ; var dashSpace = 5.0 ; double startX = 0 ; final paint = Paint ().. color = Colors . grey ; while ( max >= 0 ) { canvas.drawLine( Offset ( startX , 0 ), Offset ( startX + dashWidth , 0 ),           paint .. strokeWidth = 1 ); final space = ( dashSpace + dashWidth ); startX += space ; max -= space .toInt(); } } @override bool shouldRepaint ( CustomPainter oldDelegate) { return false ; } } Above code will paint a line of width = size. width. To use this painter as widget, we have to use CustomPaint (painter: LinePainter (),size:Size(400,1)) It will ...

How to store encryption keys safely in Android 19+?

We have to encrypt our data while saving or sending over the Internet. We have to use shared key algorithms for encryption because they are fast. But what to do with the keys, how to generate and keep them safe? Developers usually use some of the approaches mentioned below: 1. Generate shared key in the app with shared logic in app and server. This can be used for encrypting/decrypting data locally and for sending data over Internet. Problem with this approach is, app can be decompiled and logic can reconstructed. Once the logic is reconstructed hacker can keep making the keys as and when required. 2. Get key from Server and use it. Security of the key depends on how the key is transported to Mobile app. If someone can grab it, then it is compromised and can be used to decrypt data and can even be used to modify it.  Recommended approach for this is to use HTTPS connection and send key on it. Ideally new key should be used with each request, as this gives very little time to the ha...

Curious case of MissingMethodInvocationException and Mockito.when

Have you tried to mock a method in Kotlin? As mentioned in this guide we can simply use following code to make it work. //You can mock concrete classes, not just interfaces  LinkedList mockedList = mock(LinkedList.class); / /stubbing  Mockito.when(mockedList.get(0)).thenReturn("first"); If you try it on kotlin class, it will fail with exception MissingMethodInvocationException. e.g. open class DummyPresenter { fun getSomeValue():String{ return "Some Value" } } @RunWith (MockitoJUnitRunner:: class ) class ExampleUnitTest { @Test fun testCallGetSomeValue() { val presenter: DummyPresenter = mock(DummyPresenter:: class . java ) `when`(presenter.getSomeValue()).thenReturn( "Some other value" ) val result = TestClass().callGetSomeValue(presenter) println ( "Test Result: $ result " ) assertEquals( "Some other value" ,result) } } org.mockito.exceptions.misusing.MissingMethodInvocationException:  when() requi...

Flutter: How to get device details like UUID, deviceName?

We will use  device_info package for finding these details. Use this link to check latest version of the package.  Add  package_info : ^0.4.0+3 in pubspec.yaml file of your project. below  dependencies :    flutter :      sdk : flutter     package_info : ^0.4.0+3 Using next code sample you can retrieve the details. Future<List<String>> getDeviceDetails() async {     String deviceName;     String deviceVersion;     String identifier;     final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();     try {       if (Platform.isAndroid) {                  var build = await deviceInfoPlugin.androidInfo;         deviceName = build.model;         deviceVersion = build.version.toString();         identifier = build.androidId; //UUID for Android   ...