Langchain

0.0(0)
Studied by 0 people
call kaiCall Kai
Locked
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/95

flashcard set

Earn XP

Description and Tags

intro

Last updated 9:04 PM on 4/20/25
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai
Chat

No analytics yet

Send a link to your students to track their progress

96 Terms

1
New cards

What are the uses of lang chain framework

  • Build

  • Run

  • Deploy

  • Maintain

  • Monitour

2
New cards

What are some popular LLM architectures?

Examples include GPT (Generative Pre-trained Transformer), BERT (Bidirectional Encoder Representations from Transformers), and T5 (Text-to-Text Transfer Transformer).

3
New cards

LLM Task As per use case

knowt flashcard image
4
New cards

Data Loader

This is done using the source File.

Main purpose is to load the file to the model

5
New cards

what is the purpose of env file

in that we have secreat keys like open api key & lot more.

6
New cards

for text file we use ______ loader

Document Loader

7
New cards

for Single pdf file we use ______ loader

pdf loaders or pypdf

8
New cards

for Multiple pdf file we use ______ loader

Directory Loader

9
New cards

for Reasearch Paper (arvix) file we use ______ loader

Document Loader

10
New cards

how do we verify the loader ?

we can verify the loader using refrence Object

11
New cards

Text Splitter

Spliting text as per the token limit.

12
New cards

Types of text splitters

character Splitter

Recursive Character Splitter

Recursive Json Splitter

13
New cards

Character Splitter

/n ← split by next line

/n /n ← Split by paragraph

14
New cards

Chunks

Smallest part of main data for token limit

15
New cards

Chunk Overlap

This will help in maintaining the context of the Info.

16
New cards

Cosine similarity used to determine the result by

Cosine Similarity=A⋅B/∥A∥∥B∥

The result ranges between −1-1 and 11, where:

  • 11 means the vectors are identical.

  • 00 means they are orthogonal (completely different).

  • −1-1 means they are opposite

17
New cards

Indexing

Once Chunk is Created that is converted to vector with meaning.

18
New cards

if Chunk Capacity is 4k Tokens can we send 2k tokens

Yes

19
New cards

Recursive Character Splitter

This will split as per the sentance. This has the context of the words

20
New cards

Recursive Json Splitter

we will load the data from json link and we will use context manager to store File here.

21
New cards

do we send full Token

we only send 75 % of the token info

22
New cards

if your model token limit is 4k and you send documnet with 5k what happens to last1k data ?

That wont even read.

23
New cards

What is the challenge of handling token limits in LLMs?

LLMs have maximum token limits for input and output, which can make it challenging to process or generate long-form text efficiently.

24
New cards

How do LLMs handle context in a sentence or passage?

LLMs use attention mechanisms, such as in the Transformer architecture, to focus on relevant parts of the input sequence and understand context.

25
New cards

How would you choose between PyTorch and TensorFlow for training LLMs?

PyTorch is more flexible and widely used in research, while TensorFlow is production-friendly and integrates well with deployment tools.

26
New cards

what is a prompt types

system and custom prompt

27
New cards

how do you code Prmpt ?

prompt = PromptTemplate(
    input_variables=["product"],
    template="What is a good name for a company that makes {product}"
)

28
New cards

what is template and place hodler in prompt

knowt flashcard image
29
New cards

parameters that control the performance and behavior of models

Learning Rate (for training or fine-tuning)

Context Window (Token Limit)

Batch Size

Stop Sequences

Frequency Penalty

Presence Penalty

Max Tokens

Top-k

Top-p (Nucleus Sampling)

Temperature

30
New cards

Explain the parameters :

  • Temperature:

    • This parameter controls the randomness of the model's responses.

    • Low values (e.g., 0.2) make the output more focused and deterministic. The model tends to pick the highest probability answer every time.

    • High values (e.g., 0.8) make the output more diverse and creative, as it allows the model to explore less probable options.

  • Top-p (Nucleus Sampling):

    • It controls how many probabilities the model considers when generating each word or token.

    • For example:

      • Top-p = 1.0: The model considers all probabilities (like traditional sampling).

      • Top-p = 0.9: The model only considers the top 90% of probable choices and ignores the rest, leading to more focused yet flexible output.

  • Top-k:

    • This limits the number of top choices for each word the model considers.

    • Low values (e.g., k = 10) constrain the model to select from only the top 10 options, making the responses more predictable.

    • High values allow greater exploration but can lead to randomness.

  • Max Tokens:

    • This parameter sets the maximum length of the output generated.

    • Increasing this parameter allows the model to generate longer responses.

    • Reducing it limits the output length for shorter answers.

  • Presence Penalty:

    • Controls how much the model discourages repeating words or ideas it has already generated.

    • High penalty results in more diverse responses by avoiding repetitions.

    • Low penalty allows frequent repetition if required.

  • Frequency Penalty:

    • Similar to presence penalty but specifically discourages generating frequent words (e.g., common verbs).

    • Encourages more creative or novel responses.

  • Stop Sequences:

    • Specific sequences of words can be defined to stop the model's output generation.

    • For example, you might set a stop sequence like "End of conversation," and the model will cease generating text after encountering it.

  • Batch Size:

    • Controls how many predictions the model processes at once during training or inference. Larger batch sizes can speed up processing but require more memory.

  • Learning Rate (for training or fine-tuning):

    • Determines how much the model adjusts its weights during each iteration of training. A higher learning rate speeds up training but risks overshooting optimal values, while a lower rate provides stability but slows down the process.

  • Context Window (Token Limit):

    • Defines the maximum number of tokens the model can process in a single prompt. Larger context windows allow the model to understand longer inputs or conversations.

31
New cards

Chain

This will tell you order of Execution

32
New cards

if we have Multiple chains we use

Chain Channel

33
New cards

Chain Types

Simple Sequential Chain
Sequential chain

34
New cards

Simple Sequential chain

we want output of last chain

35
New cards

Sequential chain

This will give Output of all chain.

36
New cards

how do we see how chain is performing

Verbose is True

37
New cards

Agents in LLM

This will intract with LLM using

Prompt, task automation & Context handling

38
New cards

Tools in LLM

Run the query ex : external apis are used to perform external tasks.

39
New cards

memory in LLM

Help model to remember the previous chat (Conversation)

40
New cards

Conversation Memory in memory

This remember all the conversation and print only place holders values.

41
New cards

Conversation chain in memory

You get both Q& A

42
New cards

Conversation Buffer window Memory in memory

This will remember to certain number of conversation as per specified k (Context Window).

43
New cards

Embedding

This help converting text to number as model cannot understand other than number

44
New cards

Types of Embedding

Open Ai , Hugging Face , Ollama , BERT, TF IDF

45
New cards

Vector Index

This will store the embedding in your own system.

only for simple task not Company Related, only used for testing

ex FAISS

46
New cards

Vector DB

The embedding are stored in cloud

We mostly use them for Company

Ex Chroma ,Weaviate & pinecone

47
New cards

Meta data in Vector Data

This is Key Value Pair of vector.

we use this for storage limit, Character limitation & set max 50 per index.

48
New cards

How do we know a particular chunk has our related info

similarity Search (Cosine similarity , Man hat , Euclidean distance & Approximate nearest nebhour)

49
New cards

why we don’t use the SQL as vector db. ?

A custom text file has millions of texts; when we convert it, the latency will be low.

Retrieving using sql will have very bad latency as it’s not a vector db

50
New cards

Faiss full form

Facebook AI Similarity Search

51
New cards

FAISS

FAISS is widely used in applications like recommendation systems, search engines, and Large Language Model (LLM) indexing due to its ability to handle large-scale datasets with high performance.

Vector Index

No scalability

We need backup

52
New cards

what is dangerous serialization = true

you trust the dock you send to model.

earlier we used to not use this. but now this has become manditory.

53
New cards

Vector Db Types

Chroma , Weaviate & pine cone

54
New cards

Chroma

This is self hosted db. ITs from Apache.

Used for long term Retention.

55
New cards

Weaviate

Open source with Plugin and extensibility

self Hosted or Cloud

56
New cards

PineCone

This is used for cloud only.

Used mostly for scaling data sets.

57
New cards

Rag Full form

Retrieval augmented Generation

58
New cards

RAG work

retriever : this will find relevant info from query (input)

Augmentation : This takes relevant info from input to llm

Generate : Takes input of retriver & augmented to generate the output

59
New cards

Why we use a rag

As LLM cannot correctly predict from external data, we use rag.

This will remove Hallucination as this provides info that is not available to the model.

60
New cards

Finetuning Vs rag

Aspect

Fine-tuning

RAG (Retrieval-Augmented Generation)

Definition

Updates model with domain-specific data.

Combines model with external data retrieval.

Training Required

Requires retraining for new tasks.

No retraining needed; uses external sources.

Real-time Updates

Difficult to incorporate.

Easily integrates updated or live information.

Inference Speed

Faster, no external dependencies.

Slower, involves retrieving external data.

61
New cards

FineTunning

We can train a pre existing model and make that as per our requirements.

You should have Good GPU to use Fine Tuning.

62
New cards

FineTunning

LORA ,Qlora , Quantization

63
New cards

Model Compression

This will reduce the size of the model & technically complexity of model

64
New cards

drawback in model compression

Loss of accuracy

65
New cards

Types of model compression

quantization

pruning

weight sharing

knowledge distillation

66
New cards

Knowledge distillation

Train small model to mimic the behaviour of big model

67
New cards

Pruning

removing unnesary model parameters like weights so size of model is reduced

68
New cards

weight sharing

Layer of neuro share the weight thus reducing the size of model

69
New cards

Quantization

Quantization in LLMs (Large Language Models) is a technique used to make models smaller and faster by reducing the precision of the numbers they use to perform calculations.

70
New cards

Example of quantization

32 Bit FP → 8 bit FP

FP : Full Precision

Ex 1.1311341 → 1.1 FP

71
New cards

LORA vs QLORA

Aspect

LoRA (Low-Rank Adaptation)

QLoRA (Quantized LoRA)

Purpose

Efficient fine-tuning of pre-trained models.

Efficient fine-tuning combined with quantization to further reduce memory usage.

Technique

Injects low-rank matrices into model weights during training without updating the full model.

Applies LoRA fine-tuning on models quantized to 4-bit precision for extreme resource efficiency.

Memory Usage

Low memory requirements compared to full fine-tuning.

Significantly lower memory usage due to quantization (ideal for large-scale models).

Precision

Retains floating-point precision (e.g., FP32/FP16) during fine-tuning.

Reduces precision to 4-bit quantization while maintaining performance with minimal accuracy loss.

Performance

High fine-tuning efficiency, with minimal accuracy trade-off.

Comparable performance to full-precision models, despite quantization.

Computational Cost

Reduces cost by avoiding the need to train full model weights.

Further reduces computational cost by leveraging quantized models

72
New cards

Rag Types

Dense retriver : used for vector retriver Ex BERT

Sparse Retriver : Utilization like TFIDF

Hybrid : dense + Sparse

Multihop : Retriver From Multiple Steps

Personalized Retriver : Retries Based on History

73
New cards

How do we version Controll

We will use GIT

74
New cards

RAGAS

This is used to evaluate the accuracy of RAG

  • faithfulness

  • Precision

  • Recall

  • Correctness

75
New cards

Model scaling law

Model perfomance will depends on GPU

Model perfomance will decrease when the size of model increase

76
New cards

Halucination

Incorrect answer is given by model that is grammatically correct but not actually correct.

77
New cards

how do we reduce the halucination

Rag , reinforment learning , prompting , model calibraion ,Fact Verification and ensambling techniques

78
New cards

RAG in halusination

this depends on external data apart from internal data

79
New cards

Prompting in hallucination

Good prompts also reduce the hallucination

80
New cards

model calibraion

81
New cards

Fact verification

Help model to verify the facts in online

82
New cards

ensambling techniques

Combine output of multiple models to reduce hallucination

83
New cards

LLm evaluation

To Check the perfomance of LLM

Perplexity , ragas , BELU , Human , meteor

84
New cards

Perplexity:

  • Think of it as how "confused" a language model is when predicting the next word in a sentence.

  • Lower perplexity means the model is better at guessing correctly and is more confident.

85
New cards

ROUGE (Recall-Oriented Understudy for Gisting Evaluation):

  • It's a way of comparing text generated by the model with reference text.

  • It checks for overlapping words and phrases between them to measure how close they are.

  • Widely used in summarization tasks.

86
New cards

BLEU (Bilingual Evaluation Understudy):

  • A metric to evaluate how well machine-generated text matches human-written text.

  • It looks at word sequences (like pairs or triples) and rewards similarity to the reference text.

  • Commonly used in translation tasks.

87
New cards

Human Evaluation:

  • Sometimes, machines just can't do justice! Humans read the model's outputs and judge them based on quality, fluency, and relevance.

  • It's subjective but gives insight into how "natural" the model's responses are.

88
New cards

METEOR (Metric for Evaluation of Translation with Explicit Ordering):

  • Similar to BLEU, but smarter about matching synonyms and different word orders.

  • It's designed to capture the meaning better than just exact word matches.

89
New cards

How do you choose The LLm Model

its said by client as per budget or some time we suggest him better option if available

using llm evalutaion we check which model is performing good and later decide to select that model

for open source GPU and storage must be good

90
New cards

which is costly open source or non open source

non open source (GPT) but open source (LLama)has storage cost

91
New cards

which model have privacy concerns

Open source

92
New cards

Easy to change Things is model

non open source is easy to change the model as we only change the model name buy in open source we need to make a lot of changes

93
New cards

Multi stage environment

Data ingestion , Chunking , embedding , Retrieval , Generation of summary

94
New cards

Context Learning

The model is learned by based on the context provided by the model.

we provide example for what type of answer we want.

95
New cards

security Features in Azure Open Ai

Content filter (remove Hateful media), data encryption & windows defender for cloud.

96
New cards

PII management without exposing to end user :

Encryption data is stored

Role based access

Strong Authentication

monitor unauthorised acess