จาก vector สู่กราฟ

Retrieval Augmented Generation (RAG) ด้วย LangChain

Meri Nova

Machine Learning Engineer

ข้อจำกัดของ Vector RAG

ขั้นตอนทั่วไปของ RAG แบบ vector store

ฟองที่มีข้อความว่า "themes and relationships"

Retrieval Augmented Generation (RAG) ด้วย LangChain

ข้อจำกัดของ Vector RAG

ขั้นตอนทั่วไปของ RAG แบบ vector store

ฟองที่มีข้อความว่า "scalability"

Retrieval Augmented Generation (RAG) ด้วย LangChain

ข้อจำกัดของ Vector RAG

ขั้นตอนทั่วไปของ RAG แบบ vector store

ฟองที่มีข้อความว่า "integrating diverse data"

Retrieval Augmented Generation (RAG) ด้วย LangChain

ฐานข้อมูลกราฟ

กราฟแสดงความเชื่อมโยงระหว่างบุคคล สถานที่ และความสนใจ

Retrieval Augmented Generation (RAG) ด้วย LangChain

ฐานข้อมูลกราฟ - โหนด

กราฟแสดงความเชื่อมโยงระหว่างบุคคล สถานที่ และความสนใจ

Retrieval Augmented Generation (RAG) ด้วย LangChain

ฐานข้อมูลกราฟ - เอดจ์

กราฟแสดงความเชื่อมโยงระหว่างบุคคล สถานที่ และความสนใจ

Retrieval Augmented Generation (RAG) ด้วย LangChain

ฐานข้อมูลกราฟ Neo4j

 

โลโก้ Neo4j

โลโก้ LangChain

Retrieval Augmented Generation (RAG) ด้วย LangChain

จากรูปภาพสู่กราฟ...

กราฟแสดงความเชื่อมโยงระหว่างบุคคล สถานที่ และความสนใจ

Retrieval Augmented Generation (RAG) ด้วย LangChain

จากรูปภาพสู่กราฟ...

barcelona_graph.jpg

Retrieval Augmented Generation (RAG) ด้วย LangChain

จากรูปภาพสู่กราฟ...

barcelona_graph.jpg

Retrieval Augmented Generation (RAG) ด้วย LangChain

โหลดและแบ่งหน้า Wikipedia เป็นชิ้นส่วน

from langchain_community.document_loaders import WikipediaLoader
from langchain_text_splitters import TokenTextSplitter

raw_documents = WikipediaLoader(query="large language model").load()

text_splitter = TokenTextSplitter(chunk_size=100, chunk_overlap=20) documents = text_splitter.split_documents(raw_documents[:3]) print(documents[0])
page_content='A large language model (LLM) is a computational model capable of...' 
metadata={'title': 'Large language model',
          'summary': "A large language model (LLM) is...",
          'source': 'https://en.wikipedia.org/wiki/Large_language_model'}
Retrieval Augmented Generation (RAG) ด้วย LangChain

จากข้อความสู่กราฟ!

from langchain_openai import ChatOpenAI

from langchain_experimental.graph_transformers import LLMGraphTransformer
llm = ChatOpenAI(api_key="...", temperature=0, model_name="gpt-4o-mini")
llm_transformer = LLMGraphTransformer(llm=llm)
graph_documents = llm_transformer.convert_to_graph_documents(documents) print(graph_documents)
Retrieval Augmented Generation (RAG) ด้วย LangChain

จากข้อความสู่กราฟ!

[GraphDocument(
    nodes=[
        Node(id='Llm', type='Computational model'),
        Node(id='Language Generation', type='Concept'),
        Node(id='Natural Language Processing Tasks', type='Concept'),
        Node(id='Llama Family', type='Computational model'),
        Node(id='Ibm', type='Organization'),
        ..., Node(id='Bert', type='Computational model')],
    relationships=[
        Relationship(source=Node(id='Llm', type='Computational model'),
                     target=Node(id='Language Generation', type='Concept'),
                     type='CAPABLE_OF'),
        ...])]
Retrieval Augmented Generation (RAG) ด้วย LangChain

มาฝึกกันเถอะ!

Retrieval Augmented Generation (RAG) ด้วย LangChain

Preparing Video For Download...