Posts

Showing posts from March, 2025

BFF: Revolutionizing API Communication for Frontend and Backend

Image
Q. Why choose Backend for Frontend? Doesn’t it add unnecessary complexity? A. Not really. The benefits far outweigh the added layer of complexity, such as: Tighter Coupling: BFF connects the UI with backend services without exposing backend details directly to the UI. UI-Specific Logic: Allows for handling frontend-specific needs like error management, pagination, and more. Performance Optimization: Caches responses to reduce unnecessary backend calls when data hasn’t changed. Data Aggregation: Combines data from multiple services into a single response, reducing the need for the UI to make multiple API calls. Tailored Communication: Different UIs can interact with their own BFFs, without sharing the same backend logic. Network Security: The browser’s network tab only exposes what the BFF wants, mapping only the required fields. Old way: Angular --> Backend API (micro-services, 3rd party APIs) BFF way: Angular -> BFF -> Backend API (micro-services, 3rd party APIs) Below examp...

Angular Multi-repo Micro-Apps: Sharing Singleton services

Image
With reference to the apps we already have set up, Disclaimer: This is just to demonstrate a shared state. Not to be used in an ideal login/logout scenario. The best way to handle login/logouts are to use httpOnly cookies that use a token in BFF layer Let's say we we want to handle user's authentication create a folder, i am calling it "shared-library" cd shared-library ng new shared-library --create-application=false ng generate library KavyaMyUserServiceLibrary (cant use too generic names, it will not allow for public publish) Inside shared-library\shared-library\projects\user-service-library\src\lib\user-service-library.service.ts import { Injectable } from '@angular/core' ; import { BehaviorSubject } from 'rxjs' ; @ Injectable ({   providedIn : 'root' }) export class UserServiceLibraryService {   constructor () { }   private loggedIn = new BehaviorSubject < boolean >( false );   loggedIn$ = this . loggedIn . asObservable...

RAG: Pinecone, LangChain, OpenAI

Image
GITHUB Imports: import * as dotenv from "dotenv" ; import { Pinecone } from '@pinecone-database/pinecone' ; import { DirectoryLoader } from "langchain/document_loaders/fs/directory" ; import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf" ; import { RecursiveCharacterTextSplitter } from "@langchain/textsplitters" ; import { OpenAIEmbeddings } from "@langchain/openai" ; import { ChatPromptTemplate } from "@langchain/core/prompts" ; import { ChatOpenAI } from "@langchain/openai" ; 1. Initialize Environment & Dependencies Why? To load configuration and set up necessary APIs (Pinecone, LangChain, OpenAI). Load environment variables ( dotenv.config() ). Initialize Pinecone client with API key. import * as dotenv from "dotenv" ; import { Pinecone } from '@pinecone-database/pinecone' ; dotenv . config (); const pc = new Pinecone ({    ...

Vector Embeddings and Vector Storage

Image
OVERVIEW Vector Embeddings:  https://platform.openai.com/docs/api-reference/embeddings Vector Storage:  https://www.singlestore.com/ Reference:  YouTube VECTOR EMBEDDINGS Ex: A simple text "Dog" could be represented in a vector format. This is the format Machine Learning understands.  OpenAI already gives us an API we can use to convert any string or an array into a vector format To visualize a vector: Image a 2-D graph plotted to represent the words "book","page","dog","cat" When plotted on a graph, "book" and "page" have a similar semantic meaning. They are plotted closer. Same goes to "dog" and "cat". Vector is similar to an array. But not 2-D. Our example just has X, Y axis.  Imagine thousands of dimensions to plot a text, which our brain cannot really visualize.  This same word "dog" in vector representation has ~1500 items in the array. 1500 Dimensions!, each representing some lear...

NodeJS: Finetuning LLMs

Image
GITHUB Neural Network Type of Machine Learning model inspired by the way human brain works.  They are made up of layers of connected nodes called "neurons" which process data They improve over time by recognizing patterns and making decisions LLM L: Large LM: Language Model Its called "Large" because they have billions of parameters. "Language Model" because they deal with tasks that are language related like question-answering, translation, sentiment analysis etc LLM is a Deep Learning Model that is trained on vast amount of data to Understand, Generate and Respond to human-like text LLM is just one powerful tool inside the large toolbox of NLP Ex: Grammarly is an NLP system but not an LLM because it isn’t trained on a large scale using deep learning models like transformers . However, it can still analyze and process human language. Transformers? What is that? 😕 Imagine you're reading a long book, and you want to understand how different sentence...