De vectores a grafos

Retrieval Augmented Generation (RAG) con LangChain

Meri Nova

Machine Learning Engineer

Limitaciones de RAG vectorial

El flujo típico de RAG con almacén vectorial.

Un globo con "temas y relaciones".

Retrieval Augmented Generation (RAG) con LangChain

Limitaciones de RAG vectorial

El flujo típico de RAG con almacén vectorial.

Un globo con "escalabilidad".

Retrieval Augmented Generation (RAG) con LangChain

Limitaciones de RAG vectorial

El flujo típico de RAG con almacén vectorial.

Un globo con "integración de datos diversos".

Retrieval Augmented Generation (RAG) con LangChain

Bases de datos de grafos

Un grafo que muestra conexiones entre personas, lugares e intereses.

Retrieval Augmented Generation (RAG) con LangChain

Bases de datos de grafos: nodos

Un grafo que muestra conexiones entre personas, lugares e intereses.

Retrieval Augmented Generation (RAG) con LangChain

Bases de datos de grafos: aristas

Un grafo que muestra conexiones entre personas, lugares e intereses.

Retrieval Augmented Generation (RAG) con LangChain

Bases de datos grafo Neo4j

 

El logotipo de Neo4j.

El logotipo de LangChain.

Retrieval Augmented Generation (RAG) con LangChain

De gráficos a grafos...

Un grafo que muestra conexiones entre personas, lugares e intereses.

Retrieval Augmented Generation (RAG) con LangChain

De gráficos a grafos...

barcelona_graph.jpg

Retrieval Augmented Generation (RAG) con LangChain

De gráficos a grafos...

barcelona_graph.jpg

Retrieval Augmented Generation (RAG) con LangChain

Cargar y dividir páginas de 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) con LangChain

¡De texto a grafos!

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) con LangChain

¡De texto a grafos!

[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) con LangChain

¡Vamos a practicar!

Retrieval Augmented Generation (RAG) con LangChain

Preparing Video For Download...