Từ vector đến đồ thị

Retrieval Augmented Generation (RAG) với LangChain

Meri Nova

Machine Learning Engineer

Hạn chế của Vector RAG

Quy trình RAG dùng vector store điển hình.

Một bong bóng chứa "chủ đề và mối quan hệ".

Retrieval Augmented Generation (RAG) với LangChain

Hạn chế của Vector RAG

Quy trình RAG dùng vector store điển hình.

Một bong bóng chứa "khả năng mở rộng".

Retrieval Augmented Generation (RAG) với LangChain

Hạn chế của Vector RAG

Quy trình RAG dùng vector store điển hình.

Một bong bóng chứa "tích hợp dữ liệu đa dạng".

Retrieval Augmented Generation (RAG) với LangChain

Cơ sở dữ liệu đồ thị

Một đồ thị thể hiện kết nối giữa người, địa điểm và sở thích.

Retrieval Augmented Generation (RAG) với LangChain

Cơ sở dữ liệu đồ thị - nút (node)

Một đồ thị thể hiện kết nối giữa người, địa điểm và sở thích.

Retrieval Augmented Generation (RAG) với LangChain

Cơ sở dữ liệu đồ thị - cạnh (edge)

Một đồ thị thể hiện kết nối giữa người, địa điểm và sở thích.

Retrieval Augmented Generation (RAG) với LangChain

Cơ sở dữ liệu đồ thị Neo4j

 

Logo Neo4j.

Logo LangChain.

Retrieval Augmented Generation (RAG) với LangChain

Từ đồ họa đến đồ thị...

Một đồ thị thể hiện kết nối giữa người, địa điểm và sở thích.

Retrieval Augmented Generation (RAG) với LangChain

Từ đồ họa đến đồ thị...

barcelona_graph.jpg

Retrieval Augmented Generation (RAG) với LangChain

Từ đồ họa đến đồ thị...

barcelona_graph.jpg

Retrieval Augmented Generation (RAG) với LangChain

Tải và chia khúc trang 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) với LangChain

Từ văn bản thành đồ thị!

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) với LangChain

Từ văn bản thành đồ thị!

[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) với LangChain

Cùng luyện tập nào!

Retrieval Augmented Generation (RAG) với LangChain

Preparing Video For Download...