RAG using GenAI and Oracle23ai Vector Search

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

1/48

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 1:03 PM on 3/13/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

49 Terms

1
New cards

OCI GenAI and Langchain integration

langchain_community provides a wrapper class for using OCI GenAI as LLM in Langchain applications

langchain_community.llms.OCIGenAI

2
New cards

Langchain application components

  • LLMs

  • Prompts

  • Document Loaders

  • Memory

  • Vector stores

  • Chains

3
New cards

Langchain Models types

LLM - Text completion models, string input, string output

Chat models - LLM tuned for having converstations. chat messages input, AI message as output

4
New cards

Langchain Prompts

Created using Prompt templates

  1. String prompt template

  2. Chat prompt template

5
New cards

Chat prompt template

  • Supports a list of messages

  • Each chat message has content + additional parameter called ROLE

6
New cards

Langchain Chains

Used to create chains of components, including LLMs and other types of components

Created using

  1. LCEL

  2. Legacy - python classes like LLM chain, etc

7
New cards

Langchain Expression Language (LCEL)

Create chains declaratively using LCEL

8
New cards

Langchain Prompt, Model, Chain interaction

User query + Prompt (can be from Prompt template) → Prompt value → LLM → Respose

Chain → Prompt | llm

9
New cards

Langchain Memory

To store information about past interactions

10
New cards

Chain interacts with memory twice in a run

  1. After User input but Before chat execution - Read from Memory

  2. After Core logic but Before Output - Write to Memory

Chain retrieves the converstation from memory ising key and passes it to the LLM along with question. Once a new answer is returned, it writes back the query and answer to the memory

11
New cards

Memory types

Summary of contents

extracted entities like Names

12
New cards

OCI GenAI and Oracle 23ai Integration

Langchain supports Oracle23ai as Vector store

Offers python classes to store and search embeddings in Oracle 23ai vector store

OCI GenAI used to generate embeddings outside the db, using DB UTILS and REST APIs.

SELECT AI can use OCI GenAI to generate SQL to query data stored in DB using natural language.

13
New cards

Retrieval Augmented Generation RAG

Method of generating text using additional information fetched from an external data source

  • Retrieve documents and pass them a seq2seq model

14
New cards

RAG Benefits

  • Mitigate bias in training data as RAG picks data from other sources

  • Overcome model limitations like token limits, only topk search results are fed to LLM instead of whole document.

  • Handle queries without retraining

15
New cards

RAG Pipeline

  1. INGESTION

  2. RETRIEVAL

  3. GENERATION

16
New cards

****** INGESTION *****

Loading the documents

Documents broken to chunks

Embedding of chunks

Indexing in a database

<p><span style="color: red;"><strong>Loading the documents </strong></span></p><p><span style="color: red;"><strong>Documents broken to chunks</strong></span></p><p><span style="color: red;"><strong>Embedding of chunks</strong></span></p><p><span style="color: red;"><strong>Indexing in a database</strong></span></p><img src="https://assets.knowt.com/user-attachments/1e23ec34-f08f-4862-b71a-ac7349a744e9.png" data-width="100%" data-align="center" alt=""><p></p>
17
New cards

***** RETRIEVAL *****

Query → Index → Top K Results

Most relevant chunks retrieved

<p><span style="color: red;"><strong>Query → Index → Top K Results</strong></span></p><p><span style="color: red;"><strong>Most relevant chunks retrieved</strong></span></p><img src="https://assets.knowt.com/user-attachments/13f82a15-a53b-480f-99a3-3c6c6866664b.png" data-width="100%" data-align="center" alt=""><p></p>
18
New cards

***** GENERATION *****

Generates a response based on the information retrieved

Selected chunks from Retrieval phase are fed into a generative model

Generative model - Neural network like a transformer

Coherent and contextually relevant response generated

knowt flashcard image

<p>Generates a response based on the information retrieved</p><p>Selected chunks from Retrieval phase are fed into a generative model</p><p>Generative model - Neural network like a transformer</p><p>Coherent and contextually relevant response generated</p><img src="https://assets.knowt.com/user-attachments/7c357668-03cc-4025-89b5-c01f33eccb65.png" data-width="100%" data-align="center" alt="knowt flashcard image"><p></p>
19
New cards

Document Loading

Document loaders used

Data formats - PDF,CSV,HTML,JSON,Web pages, markdown

All docs from a directory can be loaded

20
New cards

Chunking

Text splitters used to split document into chunks

Chunk size - depends on the input size constraints and the context window size

Too small → Not useful semantically

Too large → Not specific semantically

21
New cards

Chunk Overlap

number of overlapping characters between adjacent chunks

Preserves context between chunks

Helps to create a richer prompt

22
New cards

Splitting method.

Default separators - [“\n\n” “\n”, “ “, ““ ]

To keep the chunk semantically meaningful

First tries to retain paragraph, if not sentence, if not word

23
New cards

Read and Split documents

RecursiveCharacterTextSplitter from langchain.text_splitter

BaseDocumentTransformer, Document from langchain_core.documents

text_splitter = RecursiveCharacterTextSplitter - chunksize, chunkoverlap

chunks = text_splitter.split_text(text)

24
New cards

Generating vector embeddings inside Oracle DB 23ai

  1. Download pretrained embedding models

  2. Convert to ONNX format

  3. Import ONNX format models to DB 23ai

25
New cards

Vector Datatype

Stores vector embeddings alongside other business data

26
New cards

Add metadata to chunks and create documents

Document object with page content and metadata

Create a dictionary representing a row of data with keys for id, link and text

Iterate through chunks, extract each page number, and actual text content of the chunk and then create a dictionary using the ID, link and text as keys

Pass dictionary to Docs wrapper function

Function returns a document which wraps metadata and page content

27
New cards

Embed documents and store in the vector database

OracleVS from langchain_communit.vectorstores.oraclevs OCIGenAIEmbeddings from langchain_community.embeddings

DistanceStrategy from langchain_community.vectorstores.utils

embed_model = OCIGenAIEmbeddings (model_id, service_endpoint, compartment_id, auth_type)

knowledge_base = OracleVS.from_documents(docs,embed_model, client, table_name, distancestrategy.DOT_PRODUCT)

28
New cards

Retrieval

User query → Encoded as a vector → sent to AI vector search

AI vector search finds documents that match the users question

29
New cards

DOT Product

Magnitude of projection of one vector onto the other.

Considers magnitude and angle

More magnitude → semantically richer content

30
New cards

COSINE product

Considers only angle between vectors and not magnitude

Less Angle → More similar

31
New cards

Vector Indexes

Specialized data structures designed for similarity searches in high dimensional vector spaces

Uses techniques like Clustering, Partitioning, Neighbour graphs to group similar vectors together

32
New cards

Oracle AI Vector search supports which index types

HNSW → In-memory Neighbour Graph Vector Index

IVF → Neighbour Partition Vector index

33
New cards

Retrieve documents and get response from LLM

RetrievalQA from langchain.chains

retv = vs.as_retriever(search_type=”similarity”, search_kwargs={k:3}

llm = ChatOCIGenAI ( model, service endpoint, comptid, auth_type)

chain = retrievalQA.from_chain_type(llm, retv , return_source_documents=True)

response = chain.invoke(“Tex”)

34
New cards

Langchain python

chain = prompt | llm

response = chain.invoke

35
New cards

Langchain memory

ConversationBufferMemory from langchain.memory

memory = ConversationBufferMemory()

memory.chat_memory

36
New cards

Oracle 23ai DB ports

1521/22

37
New cards

OCI GenAI Agents

Fully managed service that combines power of llms with an intelligent retrieval system aimed at creating contextually relevant answers by searching your knowledge base.

Ex. AI agent to book flight ticket with room booking

Applications of LLMs that are Packaged and validated ,ready to use out-of-the-box

38
New cards

LLM tasks in AI agent

Reasoning

Acting

Persona

Planning

39
New cards

Input for AI agent

Short/long term memory

Tools

Prompt

Knowledge

40
New cards

AI Agent can

  • Perform complex tasks on its own

  • Mimics human chainofthought processing

  • Effective tool for automating processes

  • Utilize knowledge

41
New cards

AI Agents Concepts

GenAI model

Agent

Knowledge Base

Data Source and Data Store

Data Ingestion

42
New cards

Answerability

Model can generate relevant responses to different user queries

43
New cards

Groundedness

Model generated responses should be tracked to different data sources

44
New cards

Agent Concepts

Session

Agent Endpoint

Trace

Citation

Content Moderation

45
New cards

AI agents can read pdf

Charts - 2d with labeled axes

Tables - with rows and columns

URLs - as is

46
New cards

Number of endpoints that you can create for each agent

Default = 3

47
New cards

No. of files

1000

48
New cards

No. of knowledge bases per tenancy

Default = 3

49
New cards

Explore top notes

note
Algebra1 SOL Brain Dump
Updated 686d ago
0.0(0)
note
AP LANG
Updated 214d ago
0.0(0)
note
Ecology Basics
Updated 533d ago
0.0(0)
note
HBS EOC REVIEW
Updated 640d ago
0.0(0)
note
les régions de la France
Updated 1236d ago
0.0(0)
note
Algebra1 SOL Brain Dump
Updated 686d ago
0.0(0)
note
AP LANG
Updated 214d ago
0.0(0)
note
Ecology Basics
Updated 533d ago
0.0(0)
note
HBS EOC REVIEW
Updated 640d ago
0.0(0)
note
les régions de la France
Updated 1236d ago
0.0(0)

Explore top flashcards

flashcards
Intro to Business - Final
49
Updated 1154d ago
0.0(0)
flashcards
FLEX - Numbers 1-20
20
Updated 192d ago
0.0(0)
flashcards
Hous book 4
47
Updated 1d ago
0.0(0)
flashcards
Digital SAT Vocabulary
991
Updated 667d ago
0.0(0)
flashcards
Vert bio fish anatomy
146
Updated 1d ago
0.0(0)
flashcards
IMENICE
24
Updated 392d ago
0.0(0)
flashcards
Intro to Business - Final
49
Updated 1154d ago
0.0(0)
flashcards
FLEX - Numbers 1-20
20
Updated 192d ago
0.0(0)
flashcards
Hous book 4
47
Updated 1d ago
0.0(0)
flashcards
Digital SAT Vocabulary
991
Updated 667d ago
0.0(0)
flashcards
Vert bio fish anatomy
146
Updated 1d ago
0.0(0)
flashcards
IMENICE
24
Updated 392d ago
0.0(0)