docs.llamaindex.ai Open in urlscan Pro
2606:4700::6812:a3  Public Scan

Submitted URL: https://memgraph24563.acemlnb.com/lt.php?x=3DZy~GDGU3Ga75F6zN64UOlu3a2gjdTyw-41XqLDKnaa750uz0y.zeFz1o2hkNM~jvYwY5nJ
Effective URL: https://docs.llamaindex.ai/en/stable/api_reference/storage/graph_stores/memgraph/
Submission: On November 22 via manual from BR — Scanned from DE

Form analysis 1 forms found in the DOM

<form class="md-header__option" data-md-component="palette">
  <input class="md-option" data-md-color-media="(prefers-color-scheme)" data-md-color-scheme="default" data-md-color-primary="indigo" data-md-color-accent="indigo" aria-label="Switch to light mode" type="radio" name="__palette" id="__palette_0">
  <label class="md-header__button md-icon" title="Switch to light mode" for="__palette_1">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
      <path d="m14.3 16-.7-2h-3.2l-.7 2H7.8L11 7h2l3.2 9zM20 8.69V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12zm-9.15 3.96h2.3L12 9z"></path>
    </svg>
  </label>
  <input class="md-option" data-md-color-media="(prefers-color-scheme: light)" data-md-color-scheme="default" data-md-color-primary="white" data-md-color-accent="purple" aria-label="Switch to dark mode" type="radio" name="__palette" id="__palette_1">
  <label class="md-header__button md-icon" title="Switch to dark mode" for="__palette_2" hidden="">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
      <path d="M12 8a4 4 0 0 0-4 4 4 4 0 0 0 4 4 4 4 0 0 0 4-4 4 4 0 0 0-4-4m0 10a6 6 0 0 1-6-6 6 6 0 0 1 6-6 6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"></path>
    </svg>
  </label>
  <input class="md-option" data-md-color-media="(prefers-color-scheme: dark)" data-md-color-scheme="slate" data-md-color-primary="black" data-md-color-accent="purple" aria-label="Switch to system preference" type="radio" name="__palette"
    id="__palette_2">
  <label class="md-header__button md-icon" title="Switch to system preference" for="__palette_0" hidden="">
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
      <path d="M12 18c-.89 0-1.74-.2-2.5-.55C11.56 16.5 13 14.42 13 12s-1.44-4.5-3.5-5.45C10.26 6.2 11.11 6 12 6a6 6 0 0 1 6 6 6 6 0 0 1-6 6m8-9.31V4h-4.69L12 .69 8.69 4H4v4.69L.69 12 4 15.31V20h4.69L12 23.31 15.31 20H20v-4.69L23.31 12z"></path>
    </svg>
  </label>
</form>

Text Content

Skip to content

LlamaIndex
Memgraph

SearchK
 * Home
 * Learn
 * Use Cases
 * Examples
 * Component Guides
 * Advanced Topics
 * API Reference
 * Open-Source Community
 * LlamaCloud

LlamaIndex
 * Home
   Home
    * High-Level Concepts
    * Installation and Setup
    * How to read these docs
    * Starter Examples
      Starter Examples
       * Starter Tutorial (OpenAI)
       * Starter Tutorial (Local Models)
   
    * Discover LlamaIndex Video Series
    * Frequently Asked Questions (FAQ)
    * Starter Tools
      Starter Tools
       * RAG CLI

 * Learn
   Learn
    * Using LLMs
    * Building a RAG pipeline
      Building a RAG pipeline
       * Loading & Ingestion
         Loading & Ingestion
          * Loading Data (Ingestion)
          * LlamaHub
          * Loading from LlamaCloud
      
       * Indexing & Embedding
       * Storing
       * Querying
   
    * Building an agent
      Building an agent
       * Agents with local models
       * Adding RAG to an agent
       * Enhancing with LlamaParse
       * Memory
       * Adding other tools
   
    * Building Workflows
      Building Workflows
       * A basic workflow
       * Branches and loops
       * Maintaining state
       * Streaming events
       * Concurrent execution
       * Subclassing workflows
       * Nested workflows
       * Observability
       * Unbound syntax
   
    * Structured Data Extraction
      Structured Data Extraction
       * Using Structured LLMs
       * Structured Prediction
       * Lower-level extraction
   
    * Tracing and Debugging
    * Evaluating
      Evaluating
       * Evaluating
       * Cost Analysis
         Cost Analysis
          * Usage Pattern
   
    * Putting it all Together
      Putting it all Together
       * Full-stack web application
         Full-stack web application
          * A Guide to Building a Full-Stack Web App with LLamaIndex
          * A Guide to Building a Full-Stack LlamaIndex Web App with Delphic
      
       * Q&A Patterns
         Q&A Patterns
          * A Guide to Extracting Terms and Definitions
      
       * Chatbots
         Chatbots
          * How to Build a Chatbot
      
       * Structured data
         Structured data
       * Agents

 * Use Cases
   Use Cases
    * Prompting
    * Question-Answering (RAG)
    * Chatbots
    * Structured Data Extraction
    * Agents
    * Multi-Modal Applications
    * Fine-Tuning

 * Examples
   Examples
    * Agents
      Agents
       * ๐Ÿ’ฌ๐Ÿค– How to Build a Chatbot
       * GPT Builder Demo
       * Building a Multi-PDF Agent using Query Pipelines and HyDE
       * Step-wise, Controllable Agents
       * Controllable Agents for RAG
       * Building an Agent around a Query Pipeline
       * Agentic rag using vertex ai
       * Agentic rag with llamaindex and vertexai managed index
       * Function Calling Anthropic Agent
       * Function Calling AWS Bedrock Converse Agent
       * Chain-of-Abstraction LlamaPack
       * Building a Custom Agent
       * DashScope Agent Tutorial
       * Introspective Agents: Performing Tasks With Reflection
       * Language Agent Tree Search
       * LLM Compiler Agent Cookbook
       * Simple Composable Memory
       * Vector Memory
       * Function Calling Mistral Agent
       * Multi-Document Agents (V1)
       * Multi-Document Agents
       * Function Calling NVIDIA Agent
       * Sub Question Query Engine powered by NVIDIA NIMs
       * Build your own OpenAI Agent
       * Context-Augmented OpenAI Agent
       * OpenAI Agent Workarounds for Lengthy Tool Descriptions
       * Single-Turn Multi-Function Calling OpenAI Agents
       * OpenAI Agent + Query Engine Experimental Cookbook
       * OpenAI Agent Query Planning
       * Retrieval-Augmented OpenAI Agent
       * OpenAI Agent with Tool Call Parser
       * OpenAI Agent with Query Engine Tools
       * OpenAI Assistant Agent
       * OpenAI Assistant Advanced Retrieval Cookbook
       * OpenAI agent: specifying a forced function call
       * Benchmarking OpenAI Retrieval API (through Assistant Agent)
       * ReAct Agent - A Simple Intro with Calculator Tools
       * ReAct Agent with Query Engine (RAG) Tools
       * Controlling Agent Reasoning Loop with Return Direct Tools
       * Structured Planning Agent
   
    * Chat Engines
      Chat Engines
       * Chat Engine - Best Mode
       * Chat Engine - Condense Plus Context Mode
       * Chat Engine - Condense Question Mode
       * Chat Engine - Context Mode
       * Chat Engine - OpenAI Agent Mode
       * Chat Engine with a Personality โœจ
       * Chat Engine - ReAct Agent Mode
       * Chat Engine - Simple Mode REPL
   
    * Cookbooks
      Cookbooks
       * GraphRAG Implementation with LlamaIndex
       * GraphRAG Implementation with LlamaIndex - V2
       * AirtrainAI Cookbook
       * Anthropic Haiku Cookbook
       * Trustworthy RAG with the Trustworthy Language Model
       * Codestral from MistralAI Cookbook
       * Cohere init8 and binary Embeddings Retrieval Evaluation
       * Contextual Retrieval
       * CrewAI + LlamaIndex Cookbook
       * Llama3 Cookbook
       * Llama3 Cookbook with Groq
       * Llama3 Cookbook with Ollama and Replicate
       * MistralAI Cookbook
       * mixedbread Rerank Cookbook
       * Optimizing for relevance using MongoDB and LlamaIndex
       * Oracle AI Vector Search with Document Processing
       * Components Of LlamaIndex
       * Evaluating RAG Systems
       * Ingestion Pipeline
       * Metadata Extraction
       * Observability
       * Agents
       * Router QueryEngine and SubQuestion QueryEngine
       * Multi-Modal RAG System
       * Advanced RAG with LlamaParse
       * Prometheus-2 Cookbook
       * Sales Prospecting Workflow with Toolhouse
   
    * Customization
      Customization
       * Azure OpenAI
       * ChatGPT
       * HuggingFace LLM - Camel-5b
       * HuggingFace LLM - StableLM
       * Chat Prompts Customization
       * Completion Prompts Customization
       * Streaming
       * Streaming for Chat Engine - Condense Question Mode
   
    * Data Connectors
      Data Connectors
       * Chroma Reader
       * DashVector Reader
       * Database Reader
       * DeepLake Reader
       * Discord Reader
       * Docling Reader
       * Faiss Reader
       * Github Repo Reader
       * Google Chat Reader Test
       * Google Docs Reader
       * Google Drive Reader
       * Google Maps Text Search Reader
       * Google Sheets Reader
       * Make Reader
       * Mbox Reader
       * MilvusReader
       * MongoDB Reader
       * MyScale Reader
       * Notion Reader
       * Obsidian Reader
       * Pathway Reader
       * Pinecone Reader
       * Preprocess
       * Psychic Reader
       * Qdrant Reader
       * Slack Reader
       * Twitter Reader
       * Weaviate Reader
       * Web Page Reader
       * Zyte Serp Reader
       * Deplot Reader Demo
       * HTML Tag Reader
       * Oracle AI Vector Search: Document Processing
       * Simple Directory Reader
       * Parallel Processing SimpleDirectoryReader
       * Simple Directory Reader over a Remote FileSystem
   
    * Discover LlamaIndex
      Discover LlamaIndex
       * Discord Thread Management
   
    * Docstores
      Docstores
       * Demo: Azure Table Storage as a Docstore
       * Docstore Demo
       * Dynamo DB Docstore Demo
       * Firestore Demo
       * MongoDB Demo
       * Redis Docstore+Index Store Demo
   
    * Embeddings
      Embeddings
       * Anyscale Embeddings
       * LangChain Embeddings
       * OpenAI Embeddings
       * Aleph Alpha Embeddings
       * Bedrock Embeddings
       * Embeddings with Clarifai
       * Cloudflare Workers AI Embeddings
       * CohereAI Embeddings
       * Custom Embeddings
       * Dashscope embeddings
       * Databricks Embeddings
       * Deepinfra
       * Elasticsearch Embeddings
       * Qdrant FastEmbed Embeddings
       * Fireworks Embeddings
       * Google Gemini Embeddings
       * Gigachat
       * Google PaLM Embeddings
       * Local Embeddings with HuggingFace
       * IBM watsonx.ai
       * Local Embeddings with IPEX-LLM on Intel CPU
       * Local Embeddings with IPEX-LLM on Intel GPU
       * Optimized BGE Embedding Model using Intelยฎ Extension for Transformers
       * Jina 8K Context Window Embeddings
       * Jina Embeddings
       * Llamafile Embeddings
       * LLMRails Embeddings
       * MistralAI Embeddings
       * Mixedbread AI Embeddings
       * ModelScope Embeddings
       * Nomic Embedding
       * NVIDIA NIMs
       * Oracle Cloud Infrastructure Generative AI
       * OctoAI Embeddings
       * Ollama Embeddings
       * Local Embeddings with OpenVINO
       * Optimized Embedding Model using Optimum-Intel
       * Oracle AI Vector Search: Generate Embeddings
       * PremAI Embeddings
       * Interacting with Embeddings deployed in Amazon SageMaker Endpoint with
         LlamaIndex
       * Text Embedding Inference
       * TextEmbed - Embedding Inference Server
       * Together AI Embeddings
       * Upstage Embeddings
       * Interacting with Embeddings deployed in Vertex AI Endpoint with
         LlamaIndex
       * Voyage Embeddings
       * Yandexgpt
   
    * Evaluation
      Evaluation
       * BEIR Out of Domain Benchmark
       * ๐Ÿš€ RAG/LLM Evaluators - DeepEval
       * HotpotQADistractor Demo
       * QuestionGeneration
       * RAGChecker: A Fine-grained Evaluation Framework For Diagnosing RAG
       * Self Correcting Query Engines - Evaluation & Retry
       * Tonic Validate Evaluators
       * How to use UpTrain with LlamaIndex
       * Answer Relevancy and Context Relevancy Evaluations
       * BatchEvalRunner - Running Multiple Evaluations
       * Correctness Evaluator
       * Faithfulness Evaluator
       * Guideline Evaluator
       * Benchmarking LLM Evaluators On The MT-Bench Human Judgement
       * Benchmarking LLM Evaluators On A Mini MT-Bench (Single Grading)
       * Evaluating Multi-Modal RAG
       * Pairwise Evaluator
       * Evaluation using Prometheus model
       * Relevancy Evaluator
       * Retrieval Evaluation
       * Embedding Similarity Evaluator
       * ๐Ÿ”๏ธ Step-back prompting with workflows for RAG with Argilla
   
    * Finetuning
      Finetuning
       * How to Finetune a cross-encoder using LLamaIndex
       * Finetuning corpus embeddings using NUDGE
       * Finetune Embeddings
       * Finetuning an Adapter on Top of any Black-Box Embedding Model
       * Knowledge Distillation For Fine-Tuning A GPT-3.5 Judge (Correctness)
       * Knowledge Distillation For Fine-Tuning A GPT-3.5 Judge (Pairwise)
       * Fine Tuning MistralAI models using Finetuning API
       * Fine Tuning GPT-3.5-Turbo
       * Fine Tuning with Function Calling
       * Fine-tuning a gpt-3.5 ReAct Agent on Better Chain of Thought
       * Custom Cohere Reranker
       * Router Fine-tuning
   
    * Ingestion
      Ingestion
       * Advanced Ingestion Pipeline
       * Async Ingestion Pipeline + Metadata Extraction
       * Ingestion Pipeline + Document Management
       * Building a Live RAG Pipeline over Google Drive Files
       * Parallelizing Ingestion Pipeline
       * Redis Ingestion Pipeline
   
    * LLMs
      LLMs
       * AI21
       * Aleph Alpha
       * Anthropic
       * Anthropic Prompt Caching
       * Anyscale
       * Azure AI model inference
       * Azure OpenAI
       * Bedrock
       * Bedrock Converse
       * Cerebras
       * Clarifai LLM
       * Cleanlab Trustworthy Language Model
       * Cohere
       * DashScope LLMS
       * DataBricks
       * DeepInfra
       * EverlyAI
       * Fireworks
       * Fireworks Function Calling Cookbook
       * Friendli
       * Gemini
       * Groq
       * Hugging Face LLMs
       * IBM watsonx.ai
       * IPEX-LLM on Intel CPU
       * IPEX-LLM on Intel GPU
       * Konko
       * Langchain
       * LiteLLM
       * Replicate - Llama 2 13B
       * LlamaCPP
       * ๐Ÿฆ™ x ๐Ÿฆ™ Rap Battle
       * Llama API
       * llamafile
       * LLM Predictor
       * LM Studio
       * LocalAI
       * Maritalk
       * MistralRS LLM
       * MistralAI
       * ModelScope LLMS
       * Monster API <> LLamaIndex
       * MyMagic AI LLM
       * Neutrino AI
       * NVIDIA NIMs
       * NVIDIA NIMs
       * Nvidia TensorRT-LLM
       * NVIDIA's LLM Text Completion API
       * Nvidia Triton
       * Oracle Cloud Infrastructure Generative AI
       * OctoAI
       * Ollama - Llama 3.1
       * Ollama - Gemma
       * OpenAI
       * OpenAI JSON Mode vs. Function Calling for Data Extraction
       * OpenLLM
       * OpenRouter
       * OpenVINO LLMs
       * Optimum Intel LLMs optimized with IPEX backend
       * AlibabaCloud-PaiEas
       * PaLM
       * Perplexity
       * Pipeshift
       * Portkey
       * Predibase
       * PremAI LlamaIndex
       * Client of Baidu Intelligent Cloud's Qianfan LLM Platform
       * RunGPT
       * Interacting with LLM deployed in Amazon SageMaker Endpoint with
         LlamaIndex
       * SambaNova Cloud
       * Solar LLM
       * Together AI LLM
       * Unify
       * Upstage
       * Vertex AI
       * Replicate - Vicuna 13B
       * vLLM
       * Xorbits Inference
       * Yi
   
    * Llama Datasets
      Llama Datasets
       * Downloading a LlamaDataset from LlamaHub
       * Benchmarking RAG Pipelines With A
       * Submission Template Notebook
       * Contributing a LlamaDataset To LlamaHub
   
    * Llama Hub
      Llama Hub
       * LlamaHub Demostration
       * Ollama Llama Pack Example
       * Llama Pack - Resume Screener ๐Ÿ“„
       * Llama Packs Example
   
    * Low Level
      Low Level
       * Building Evaluation from Scratch
       * Building an Advanced Fusion Retriever from Scratch
       * Building Data Ingestion from Scratch
       * Building RAG from Scratch (Open-source only!)
       * Building Response Synthesis from Scratch
       * Building Retrieval from Scratch
       * Building a Router from Scratch
       * Building a (Very Simple) Vector Store from Scratch
   
    * Managed Indexes
      Managed Indexes
       * BGEM3Demo
       * Google Generative Language Semantic Retriever
       * PostgresML Managed Index
       * Google Cloud LlamaIndex on Vertex AI for RAG
       * Semantic Retriever Benchmark
       * Vectara Managed Index
       * Managed Index with Zilliz Cloud Pipelines
   
    * Memory
      Memory
       * Mem0
   
    * Metadata Extractors
      Metadata Extractors
       * Entity Metadata Extraction
       * Metadata Extraction and Augmentation w/ Marvin
       * Extracting Metadata for Better Document Indexing and Understanding
       * Automated Metadata Extraction for Better Retrieval + Synthesis
       * Pydantic Extractor
   
    * Multi-Modal
      Multi-Modal
       * Chroma Multi-Modal Demo with LlamaIndex
       * Multi-Modal LLM using Anthropic model for image reasoning
       * Multi-Modal LLM using Azure OpenAI GPT-4V model for image reasoning
       * Multi-Modal Retrieval using Cohere Multi-Modal Embeddings
       * Multi-Modal LLM using DashScope qwen-vl model for image reasoning
       * Multi-Modal LLM using Google's Gemini model for image understanding and
         build Retrieval Augmented Generation with LlamaIndex
       * Multimodal Structured Outputs: GPT-4o vs. Other GPT-4 Variants
       * GPT4-V Experiments with General, Specific questions and Chain Of
         Thought (COT) Prompting Technique.
       * Advanced Multi-Modal Retrieval using GPT4V and Multi-Modal
         Index/Retriever
       * Image to Image Retrieval using CLIP embedding and image correlation
         reasoning using GPT4V
       * LlaVa Demo with LlamaIndex
       * Retrieval-Augmented Image Captioning
       * Multi-Modal LLM using Mistral Pixtral-12B model for image reasoning
       * [Beta] Multi-modal ReAct Agent
       * Multi-Modal GPT4V Pydantic Program
       * Multi-Modal RAG using Nomic Embed and Anthropic.
       * Multi-Modal Retrieval using GPT text embedding and CLIP image embedding
         for Wikipedia Articles
       * Multimodal RAG for processing videos using OpenAI GPT4V and LanceDB
         vectorstore
       * Multimodal RAG with VideoDB
       * Multi-Modal LLM using NVIDIA endpoints for image reasoning
       * Multimodal Ollama Cookbook
       * Multi-Modal LLM using OpenAI GPT-4V model for image reasoning
       * Local Multimodal pipeline with OpenVINO
       * Multi-Modal LLM using Replicate LlaVa, Fuyu 8B, MiniGPT4 models for
         image reasoning
       * Semi-structured Image Retrieval
   
    * Multi-Tenancy
      Multi-Tenancy
       * Multi-Tenancy RAG with LlamaIndex
   
    * Node Parsers & Text Splitters
      Node Parsers & Text Splitters
       * Semantic Chunker
       * Semantic double merging chunking
       * TopicNodeParser
   
    * Node Postprocessors
      Node Postprocessors
       * Cohere Rerank
       * Reranking using ColPali, Cohere Reranker and Multi-Modal Embeddings
       * Colbert Rerank
       * File Based Node Parsers
       * FlagEmbeddingReranker
       * Jina Rerank
       * LLM Reranker Demonstration (Great Gatsby)
       * LLM Reranker Demonstration (2021 Lyft 10-k)
       * LongContextReorder
       * Metadata Replacement + Node Sentence Window
       * Mixedbread AI Rerank
       * NVIDIA NIMs
       * Sentence Embedding Optimizer
       * PII Masking
       * Forward/Backward Augmentation
       * Recency Filtering
       * SentenceTransformerRerank
       * Time-Weighted Rerank
       * VoyageAI Rerank
       * OpenVINO Rerank
       * RankGPT Reranker Demonstration (Van Gogh Wiki)
       * RankLLM Reranker Demonstration (Van Gogh Wiki)
   
    * Object Stores
      Object Stores
       * The Class
   
    * Observability
      Observability
       * Aim Callback
       * HoneyHive LlamaIndex Tracer
       * Langfuse Callback Handler
       * Analyze and Debug LlamaIndex Applications with PostHog and Langfuse
       * Llama Debug Handler
       * MLflow
       * OpenInference Callback Handler + Arize Phoenix
       * Observability with OpenLLMetry
       * Logging traces with Opik
       * PromptLayer Handler
       * Token Counting Handler
       * UpTrain Callback Handler
       * Wandb Callback Handler
   
    * Output Parsers
      Output Parsers
       * Guardrails Output Parsing
       * Langchain Output Parsing
       * DataFrame Structured Data Extraction
       * Evaporate Demo
       * Function Calling Program for Structured Extraction
       * Guidance Pydantic Program
       * Guidance for Sub-Question Query Engine
       * LLM Pydantic Program
       * LM Format Enforcer Pydantic Program
       * LM Format Enforcer Regular Expression Generation
       * LLM Pydantic Program - NVIDIA
       * OpenAI Pydantic Program
       * OpenAI function calling for Sub-Question Query Engine
   
    * Param Optimizer
      Param Optimizer
       * [WIP] Hyperparameter Optimization for RAG
   
    * Prompts
      Prompts
       * Advanced Prompt Techniques (Variable Mappings, Functions)
       * EmotionPrompt in RAG
       * Accessing/Customizing Prompts within Higher-Level Modules
       * "Optimization by Prompting" for RAG
       * Prompt Engineering for RAG
   
    * Property Graph
      Property Graph
       * Using a Property Graph Store
       * Property Graph Construction with Predefined Schemas
       * Property Graph Index
       * Defining a Custom Property Graph Retriever
       * Neo4j Property Graph Index
   
    * Query Engines
      Query Engines
       * Retriever Query Engine with Custom Retrievers - Simple Hybrid Search
       * JSONalyze Query Engine
       * Joint QA Summary Query Engine
       * Retriever Router Query Engine
       * Router Query Engine
       * SQL Auto Vector Query Engine
       * SQL Join Query Engine
       * SQL Router Query Engine
       * CitationQueryEngine
       * Cogniswitch query engine
       * Defining a Custom Query Engine
       * Ensemble Query Engine Guide
       * FLARE Query Engine
       * JSON Query Engine
       * Knowledge Graph Query Engine
       * Knowledge Graph RAG Query Engine
       * Structured Hierarchical Retrieval
       * Pandas Query Engine
       * Recursive Retriever + Query Engine Demo
       * [Beta] Text-to-SQL with PGVector
       * Query Engine with Pydantic Outputs
       * Recursive Retriever + Document Agents
       * Joint Tabular/Semantic QA over Tesla 10K
       * Sub Question Query Engine
   
    * Query Pipeline
      Query Pipeline
       * An Introduction to LlamaIndex Query Pipelines
       * Query Pipeline with Async/Parallel Execution
       * Query Pipeline Chat Engine
       * Query Pipeline over Pandas DataFrames
       * Query Pipeline with Routing
       * Query Pipeline for Advanced Text-to-SQL
   
    * Query Transformations
      Query Transformations
       * HyDE Query Transform
       * Multi-Step Query Engine
       * Query Transform Cookbook
   
    * Response Synthesizers
      Response Synthesizers
       * Pydantic Tree Summarize
       * Stress-Testing Long Context LLMs with a Recall Task
       * Pydantic Tree Summarize
       * Refine
       * Refine with Structured Answer Filtering
       * Tree Summarize
   
    * Retrievers
      Retrievers
       * Auto Merging Retriever
       * Comparing Methods for Structured Retrieval (Auto-Retrieval vs.
         Recursive Retrieval)
       * Bedrock (Knowledge Bases)
       * BM25 Retriever
       * Composable Objects
       * Activeloop Deep Memory
       * Ensemble Retrieval Guide
       * Chunk + Document Hybrid Retrieval with Long-Context Embeddings
         (Together.ai)
       * Pathway Retriever
       * Reciprocal Rerank Fusion Retriever
       * Recursive Retriever + Node References + Braintrust
       * Recursive Retriever + Node References
       * Relative Score Fusion and Distribution-Based Score Fusion
       * Router Retriever
       * Simple Fusion Retriever
       * Auto-Retrieval from a Vectara Index
       * Vertex AI Search Retriever
       * Videodb retriever
       * You.com Retriever
   
    * Tools
      Tools
       * OnDemandLoaderTool Tutorial
       * Azure Code Interpreter Tool Spec
       * Cassandra Database Tools
       * Evaluation Query Engine Tool
   
    * Transforms
      Transforms
       * Transforms Evaluation
   
    * Use Cases
      Use Cases
       * 10K Analysis
       * 10Q Analysis
       * Email Data Extraction
       * Github Issue Analysis
   
    * Vector Stores
      Vector Stores
       * AWSDocDBDemo
       * Alibaba Cloud OpenSearch Vector Store
       * Amazon Neptune - Neptune Analytics vector store
       * AnalyticDB
       * Astra DB
       * Simple Vector Store - Async Index Creation
       * Awadb Vector Store
       * Azure AI Search
       * Azure CosmosDB MongoDB Vector Store
       * Azure Cosmos DB No SQL Vector Store
       * Bagel Vector Store
       * Bagel Network
       * Baidu VectorDB
       * Cassandra Vector Store
       * Chroma + Fireworks + Nomic with Matryoshka embedding
       * Chroma
       * ClickHouse Vector Store
       * CouchbaseVectorStoreDemo
       * DashVector Vector Store
       * Databricks Vector Search
       * Deep Lake Vector Store Quickstart
       * DocArray Hnsw Vector Store
       * DocArray InMemory Vector Store
       * DuckDB
       * Elasticsearch Vector Store
       * Elasticsearch
       * Epsilla Vector Store
       * Faiss Vector Store
       * Firestore Vector Store
       * Hnswlib
       * Hologres
       * Jaguar Vector Store
       * Advanced RAG with temporal filters using LlamaIndex and KDB.AI vector
         store
       * LanceDB Vector Store
       * Lantern Vector Store (auto-retriever)
       * Lantern Vector Store
       * Lindorm
       * Metal Vector Store
       * Milvus Vector Store With Hybrid Retrieval
       * Milvus Vector Store
       * MilvusOperatorFunctionDemo
       * MongoDB Atlas Vector Store
       * MongoDB Atlas + Fireworks AI RAG Example
       * MongoDB Atlas + OpenAI RAG Example
       * MyScale Vector Store
       * Neo4j vector store
       * Nile Vector Store (Multi-tenant PostgreSQL)
       * ObjectBox VectorStore Demo
       * OceanBase Vector Store
       * Opensearch Vector Store
       * pgvecto.rs
       * Pinecone Vector Store - Hybrid Search
       * Pinecone Vector Store
       * Qdrant Vector Store
       * Qdrant Vector Store - Metadata Filter
       * Qdrant Vector Store - Default Qdrant Filters
       * Redis Vector Store
       * Relyt
       * Rockset Vector Store
       * Simple Vector Store
       * Local Llama2 + VectorStoreIndex
       * Llama2 + VectorStoreIndex
       * Simple Vector Stores - Maximum Marginal Relevance Retrieval
       * S3/R2 Storage
       * Supabase Vector Store
       * TablestoreVectorStore
       * Tair Vector Store
       * Tencent Cloud VectorDB
       * TiDB Vector Store
       * Timescale Vector Store (PostgreSQL)
       * txtai Vector Store
       * Typesense Vector Store
       * Upstash Vector Store
       * VearchDemo
       * Google Vertex AI Vector Search
       * Vespa Vector Store demo
       * Weaviate Vector Store - Hybrid Search
       * Weaviate Vector Store
       * Auto-Retrieval from a Weaviate Vector Database
       * Weaviate Vector Store Metadata Filter
       * WordLift Vector Store
       * Zep Vector Store
       * Auto-Retrieval from a Vector Database
       * Chroma Vector Store
       * Auto-Retrieval from a Vector Database
       * Guide: Using Vector Store Index with Existing Pinecone Vector Store
       * Guide: Using Vector Store Index with Existing Weaviate Vector Store
       * Neo4j Vector Store - Metadata Filter
       * Oracle AI Vector Search: Vector Store
       * A Simple to Advanced Guide with Auto-Retrieval (with Pinecone + Arize
         Phoenix)
       * Pinecone Vector Store - Metadata Filter
       * Postgres Vector Store
       * Hybrid Search with Qdrant BM42
       * Qdrant Hybrid Search
   
    * Workflow
      Workflow
       * JSONalyze Query Engine
       * Workflows for Advanced Text-to-SQL
       * None
       * Build RAG with in-line citations
       * Corrective RAG Workflow
       * Workflow for a Function Calling Agent
       * Choose Your Own Adventure Workflow (Human In The Loop)
       * LongRAG Workflow
       * MultiStep Query Engine
       * Multi-strategy workflow with reflection
       * Parallel Execution of Same Event Example
       * Query Planning Workflow
       * RAG Workflow with Reranking
       * Workflow for a ReAct Agent
       * Reflection Workflow for Structured Outputs
       * Router Query Engine
       * Self-Discover Workflow
       * Sub Question Query Engine as a workflow
       * Workflows cookbook: walking through all features of Workflows

 * Component Guides
   Component Guides
    * Models
      Models
       * LLMs
         LLMs
          * Using LLMs
          * Standalone Usage
          * Customizing LLMs
          * Available LLM Integrations
      
       * Embeddings
       * Multi Modal
   
    * Prompts
      Prompts
       * Usage pattern
   
    * Loading
      Loading
       * Documents and Nodes
         Documents and Nodes
          * Using Documents
          * Using Nodes
          * Metadata Extraction
      
       * SimpleDirectoryReader
       * Data Connectors
         Data Connectors
          * Usage Pattern
          * LlamaParse
          * Module Guides
      
       * Node Parsers / Text Splitters
         Node Parsers / Text Splitters
          * Node Parser Modules
      
       * Ingestion Pipeline
         Ingestion Pipeline
          * Transformations
   
    * Indexing
      Indexing
       * Index Guide
       * Vector Store Index
       * Property Graph Index
       * Document Management
       * LlamaCloud
       * Metadata Extraction
       * Modules
   
    * Storing
      Storing
       * Vector Stores
       * Document Stores
       * Index Stores
       * Chat Stores
       * Key-Value Stores
       * Persisting & Loading Data
       * Customizing Storage
   
    * Querying
      Querying
       * Query Engines
         Query Engines
          * Usage Pattern
          * Response Modes
          * Streaming
          * Module Guides
          * Supporting Modules
      
       * Chat Engines
         Chat Engines
          * Usage Pattern
          * Module Guides
      
       * Retrieval
         Retrieval
          * Retriever Modules
          * Retriever Modes
      
       * Node Postprocessors
         Node Postprocessors
          * Node Postprocessor Modules
      
       * Response Synthesis
         Response Synthesis
          * Response Synthesis Modules
      
       * Routing
       * Workflows
       * Query Pipelines (Deprecated)
         Query Pipelines (Deprecated)
          * Usage Pattern
          * Module Guides
          * Module Usage
      
       * Structured Outputs
         Structured Outputs
          * Output Parsing Modules
          * (Deprecated) Query Engines + Pydantic Outputs
          * Pydantic Programs
   
    * Agents
      Agents
       * Usage Pattern
       * Lower-Level Agent API
       * Module Guides
       * Tools
   
    * Workflows
      Workflows
    * Evaluation
      Evaluation
       * Usage Pattern (Response Evaluation)
       * Usage Pattern (Retrieval)
       * Modules
       * LlamaDatasets
         LlamaDatasets
          * Contributing A LabelledRagDataset
          * Evaluating With LabelledRagDataset's
          * Evaluating Evaluators with LabelledEvaluatorDataset's
   
    * Observability
      Observability
       * Instrumentation
   
    * Settings
    * Llama Deploy
      Llama Deploy
       * Getting Started
       * Core Components
       * Manual orchestration
       * Python SDK
       * CLI

 * Advanced Topics
   Advanced Topics
    * Building Performant RAG Applications for Production
    * Basic Strategies
    * Agentic strategies
    * Retrieval
      Retrieval
       * Advanced Retrieval Strategies
       * Query Transformations
   
    * Evaluation
      Evaluation
       * Component Wise Evaluation
       * End-to-End Evaluation
       * Evaluation
   
    * Fine-Tuning
    * Writing Custom Modules
    * Building RAG from Scratch (Lower-Level)

 * API Reference
   API Reference
    * Agents
      Agents
       * Coa
       * Dashscope
       * Introspective
       * Lats
       * Llm compiler
       * Openai
       * Openai legacy
       * React
   
    * Callbacks
      Callbacks
       * Agentops
       * Aim
       * Argilla
       * Arize phoenix
       * Deepeval
       * Honeyhive
       * Langfuse
       * Literalai
       * Llama debug
       * Openinference
       * None
       * Opik
       * Promptlayer
       * Token counter
       * Uptrain
       * Wandb
   
    * Chat Engines
      Chat Engines
       * Condense plus context
       * Condense question
       * Context
       * Simple
   
    * Embeddings
      Embeddings
       * Adapter
       * Alephalpha
       * Alibabacloud aisearch
       * Anyscale
       * Azure inference
       * Azure openai
       * Bedrock
       * Clarifai
       * Clip
       * Cloudflare workersai
       * Cohere
       * Dashscope
       * Databricks
       * Deepinfra
       * Elasticsearch
       * Fastembed
       * Fireworks
       * Gaudi
       * Gemini
       * Gigachat
       * Google
       * None
       * Huggingface
       * Huggingface api
       * Huggingface itrex
       * Huggingface openvino
       * Huggingface optimum
       * Huggingface optimum intel
       * Ibm
       * Instructor
       * Ipex llm
       * Jinaai
       * Langchain
       * Litellm
       * Llamafile
       * Llm rails
       * Mistralai
       * Mixedbreadai
       * Modelscope
       * Nomic
       * Nvidia
       * Oci genai
       * Octoai
       * Ollama
       * Openai
       * Oracleai
       * Premai
       * Sagemaker endpoint
       * Siliconflow
       * Text embeddings inference
       * Textembed
       * Together
       * Upstage
       * Vertex
       * Vertex endpoint
       * Voyageai
       * Xinference
       * Yandexgpt
       * Zhipuai
   
    * Evaluation
      Evaluation
       * Answer relevancy
       * Context relevancy
       * Correctness
       * Dataset generation
       * Faithfullness
       * Guideline
       * Metrics
       * Multi modal
       * Pairwise comparison
       * Query response
       * Response
       * Retrieval
       * Semantic similarity
       * Tonic validate
   
    * Indexes
      Indexes
       * Bge m3
       * Colbert
       * Dashscope
       * Document summary
       * Google
       * Keyword
       * Knowledge graph
       * Llama cloud
       * Postgresml
       * Property graph
       * Summary
       * Tree
       * Vectara
       * Vector
       * Vertexai
       * Zilliz
   
    * Ingestion
      Ingestion
    * Instrumentation
      Instrumentation
       * Event handlers
       * Event types
       * Span handlers
       * Span types
   
    * LLMs
      LLMs
       * None
       * Ai21
       * Alephalpha
       * Alibabacloud aisearch
       * Anthropic
       * Anyscale
       * Azure inference
       * Azure openai
       * Bedrock
       * Bedrock converse
       * Cerebras
       * Clarifai
       * Cleanlab
       * Cohere
       * Custom llm
       * Dashscope
       * Databricks
       * Deepinfra
       * Everlyai
       * Fireworks
       * Friendli
       * Gaudi
       * Gemini
       * Gigachat
       * None
       * Groq
       * Huggingface
       * Huggingface api
       * Ibm
       * Ipex llm
       * Konko
       * Langchain
       * Litellm
       * Llama api
       * Llama cpp
       * Llamafile
       * Lmstudio
       * Localai
       * Maritalk
       * Mistral rs
       * Mistralai
       * Mlx
       * Modelscope
       * Monsterapi
       * Mymagic
       * Neutrino
       * Nvidia
       * Nvidia tensorrt
       * Nvidia triton
       * Oci genai
       * Octoai
       * Ollama
       * Openai
       * Openai like
       * Openllm
       * Openrouter
       * Openvino
       * Optimum intel
       * Paieas
       * Palm
       * Perplexity
       * Pipeshift
       * Portkey
       * Predibase
       * Premai
       * Qianfan
       * Reka
       * Replicate
       * Rungpt
       * Sagemaker endpoint
       * Sambanovacloud
       * Siliconflow
       * Solar
       * Text generation inference
       * Together
       * Unify
       * Upstage
       * Vertex
       * Vllm
       * Xinference
       * Yi
       * You
       * Zhipuai
   
    * Llama Datasets
      Llama Datasets
    * Llama Deploy
      Llama Deploy
       * apiserver
       * control_plane
       * deploy
       * message_consumers
       * message_publishers
       * messages
       * orchestrators
       * Python SDK
       * services
       * types
       * message_queues
         message_queues
          * apache_kafka
          * rabbitmq
          * redis
          * simple
   
    * Llama Packs
      Llama Packs
       * Agent search retriever
       * Agents coa
       * Agents lats
       * Agents llm compiler
       * Amazon product extraction
       * Arize phoenix query engine
       * Auto merging retriever
       * Chroma autoretrieval
       * Code hierarchy
       * Cogniswitch agent
       * Cohere citation chat
       * Corrective rag
       * Deeplake deepmemory retriever
       * Deeplake multimodal retrieval
       * Dense x retrieval
       * Diff private simple dataset
       * Docugami kg rag
       * Evaluator benchmarker
       * Finchat
       * Fusion retriever
       * Fuzzy citation
       * Gmail openai agent
       * Gradio agent chat
       * Gradio react agent chatbot
       * Infer retrieve rerank
       * Koda retriever
       * Llama dataset metadata
       * Llama guard moderator
       * Llava completion
       * Longrag
       * Mixture of agents
       * Multi document agents
       * Multi tenancy rag
       * Multidoc autoretrieval
       * Nebulagraph query engine
       * Neo4j query engine
       * Node parser semantic chunking
       * Ollama query engine
       * Panel chatbot
       * Query understanding agent
       * Raft dataset
       * Rag cli local
       * Rag evaluator
       * Rag fusion query pipeline
       * Ragatouille retriever
       * Raptor
       * Recursive retriever
       * Redis ingestion pipeline
       * Resume screener
       * Retry engine weaviate
       * Searchain
       * Secgpt
       * Self discover
       * Self rag
       * Sentence window retriever
       * Snowflake query engine
       * Stock market data query engine
       * Streamlit chatbot
       * Sub question weaviate
       * Subdoc summary
       * Tables
       * Timescale vector autoretrieval
       * Trulens eval packs
       * Vanna
       * Vectara rag
       * Voyage query engine
       * Zenguard
       * Zephyr query engine
   
    * Memory
      Memory
       * Chat memory buffer
       * Mem0
       * Simple composable memory
       * Vector memory
   
    * Metadata Extractors
      Metadata Extractors
       * Entity
       * Keyword
       * None
       * Marvin
       * Pydantic
       * Question
       * Relik
       * Summary
       * Title
   
    * Multi-Modal LLMs
      Multi-Modal LLMs
       * Anthropic
       * Azure openai
       * Dashscope
       * Gemini
       * Huggingface
       * Mistralai
       * Nvidia
       * Ollama
       * Openai
       * Openvino
       * Reka
       * Replicate
       * Zhipuai
   
    * Node Parsers & Text Splitters
      Node Parsers & Text Splitters
       * Alibabacloud aisearch
       * Dashscope
       * Docling
       * Topic
       * Code
       * Hierarchical
       * Html
       * Json
       * Langchain
       * Markdown
       * Markdown element
       * Semantic splitter
       * Sentence splitter
       * Sentence window
       * Token text splitter
       * Unstructured element
   
    * Node Postprocessors
      Node Postprocessors
       * NER PII
       * PII
       * Alibabacloud aisearch rerank
       * Auto prev next
       * Cohere rerank
       * Colbert rerank
       * Colpali rerank
       * Dashscope rerank
       * Embedding recency
       * Fixed recency
       * Flag embedding reranker
       * Jinaai rerank
       * Keyword
       * Llm rerank
       * Long context reorder
       * Longllmlingua
       * Metadata replacement
       * Mixedbreadai rerank
       * Nvidia rerank
       * Openvino rerank
       * Presidio
       * Prev next
       * Rankgpt rerank
       * Rankllm rerank
       * Sbert rerank
       * Sentence optimizer
       * Siliconflow rerank
       * Similarity
       * Tei rerank
       * Time weighted
       * Voyageai rerank
       * Xinference rerank
   
    * Object Stores
      Object Stores
    * Output Parsers
      Output Parsers
       * Guardrails
       * Langchain
       * Pydantic
       * Selection
   
    * Programs
      Programs
       * Evaporate
       * Guidance
       * Llm text completion
       * Lmformatenforcer
       * Multi modal
       * Openai
   
    * Prompts
      Prompts
    * Query Engines
      Query Engines
       * FLARE
       * JSONalayze
       * NL SQL table
       * PGVector SQL
       * SQL join
       * SQL table retriever
       * Citation
       * Cogniswitch
       * Custom
       * Knowledge graph
       * Multi step
       * Pandas
       * Retriever
       * Retriever router
       * Retry
       * Router
       * Simple multi modal
       * Sub question
       * Tool retriever router
       * Transform
   
    * Query Pipeline
      Query Pipeline
       * Agent
       * Arg pack
       * Custom
       * Function
       * Input
       * Llm
       * Multi modal
       * Object
       * Output parser
       * Postprocessor
       * Prompt
       * Query engine
       * Query transform
       * Retriever
       * Router
       * Synthesizer
       * Tool runner
   
    * Question Generators
      Question Generators
       * Guidance
       * Llm question gen
       * Openai
   
    * Readers
      Readers
       * Agent search
       * Airbyte cdk
       * Airbyte gong
       * Airbyte hubspot
       * Airbyte salesforce
       * Airbyte shopify
       * Airbyte stripe
       * Airbyte typeform
       * Airbyte zendesk support
       * Airtable
       * Alibabacloud aisearch
       * Apify
       * Arango db
       * Arxiv
       * Asana
       * Assemblyai
       * Astra db
       * Athena
       * Awadb
       * Azcognitive search
       * Azstorage blob
       * Azure devops
       * Bagel
       * Bilibili
       * Bitbucket
       * Boarddocs
       * Box
       * Chatgpt plugin
       * Chroma
       * Clickhouse
       * Confluence
       * Couchbase
       * Couchdb
       * Dad jokes
       * Dashscope
       * Dashvector
       * Database
       * Deeplake
       * Discord
       * Docling
       * Docstring walker
       * Docugami
       * Document360
       * Earnings call transcript
       * Elasticsearch
       * Faiss
       * Feedly rss
       * Feishu docs
       * Feishu wiki
       * File
       * Firebase realtimedb
       * Firestore
       * Gcs
       * Genius
       * Gitbook
       * Github
       * Gitlab
       * Google
       * Gpt repo
       * Graphdb cypher
       * Graphql
       * Guru
       * Hatena blog
       * Hive
       * Hubspot
       * Huggingface fs
       * Hwp
       * Iceberg
       * Imdb review
       * Intercom
       * Jaguar
       * Jira
       * Joplin
       * Json
       * Kaltura esearch
       * Kibela
       * Lilac
       * Linear
       * Llama parse
       * Macrometa gdn
       * Make com
       * Mangadex
       * Mangoapps guides
       * Maps
       * Mbox
       * Memos
       * Metal
       * Microsoft onedrive
       * Microsoft outlook
       * Microsoft sharepoint
       * Milvus
       * Minio
       * Mondaydotcom
       * Mongodb
       * Myscale
       * Notion
       * Nougat ocr
       * Obsidian
       * Openalex
       * Openapi
       * Opendal
       * Opensearch
       * Oracleai
       * Pandas ai
       * Papers
       * Patentsview
       * Pathway
       * Pdb
       * Pdf marker
       * Pdf table
       * Pebblo
       * None
       * Preprocess
       * Psychic
       * Qdrant
       * Quip
       * Rayyan
       * Readme
       * Readwise
       * Reddit
       * Remote
       * Remote depth
       * S3
       * Sec filings
       * Semanticscholar
       * Simple directory reader
       * Singlestore
       * Slack
       * Smart pdf loader
       * Snowflake
       * Snscrape twitter
       * Spotify
       * Stackoverflow
       * Steamship
       * String iterable
       * Stripe docs
       * Structured data
       * Telegram
       * Toggl
       * Trello
       * Twitter
       * Txtai
       * Upstage
       * Weather
       * Weaviate
       * Web
       * Whatsapp
       * Wikipedia
       * Wordlift
       * Wordpress
       * Youtube metadata
       * Youtube transcript
       * Zendesk
       * Zep
       * Zulip
       * Zyte serp
   
    * Response Synthesizers
      Response Synthesizers
       * Accumulate
       * Compact accumulate
       * Compact and refine
       * Generation
       * Google
       * Refine
       * Simple summarize
       * Tree summarize
   
    * Retrievers
      Retrievers
       * Auto merging
       * Bedrock
       * Bm25
       * Duckdb retriever
       * Keyword
       * Knowledge graph
       * Mongodb atlas bm25 retriever
       * Pathway
       * Query fusion
       * Recursive
       * Router
       * Sql
       * Summary
       * Transform
       * Tree
       * Vector
       * Vertexai search
       * Videodb
       * You
   
    * Schema
      Schema
    * Selectors
      Selectors
       * Notdiamond
   
    * Sparse Embeddings
      Sparse Embeddings
       * Fastembed
   
    * Storage
      Storage
       * Chat Store
         Chat Store
          * Azure
          * Azurecosmosmongovcore
          * Azurecosmosnosql
          * Dynamodb
          * Postgres
          * Redis
          * Simple
          * Upstash
      
       * Docstore
         Docstore
          * Azure
          * Couchbase
          * Dynamodb
          * Elasticsearch
          * Firestore
          * Mongodb
          * Postgres
          * Redis
          * Simple
      
       * Graph Stores
         Graph Stores
          * Falkordb
          * Kuzu
          * Memgraph Memgraph
            Table of contents
             * MemgraphGraphStore
                * query
                * get
                * get_rel_map
                * upsert_triplet
                * delete
                * refresh_schema
                * get_schema
            
             * MemgraphPropertyGraphStore
                * refresh_schema
                * upsert_relations
                * get
                * get_rel_map
                * delete
         
          * Nebula
          * Neo4j
          * Neptune
          * Simple
          * Tidb
      
       * Index Store
         Index Store
          * Azure
          * Azurecosmosnosql
          * Couchbase
          * Dynamodb
          * Elasticsearch
          * Firestore
          * Mongodb
          * Postgres
          * Redis
          * Simple
      
       * Kvstore
         Kvstore
          * Azure
          * Azurecosmosnosql
          * Couchbase
          * Dynamodb
          * Elasticsearch
          * Firestore
          * Mongodb
          * Postgres
          * Redis
          * S3
          * Simple
      
       * Storage
         Storage
          * Storage context
      
       * Vector Store
         Vector Store
          * Alibabacloud opensearch
          * Analyticdb
          * Astra db
          * Awadb
          * Awsdocdb
          * Azureaisearch
          * Azurecosmosmongo
          * Azurecosmosnosql
          * Bagel
          * Baiduvectordb
          * Cassandra
          * Chatgpt plugin
          * Chroma
          * Clickhouse
          * Couchbase
          * Dashvector
          * Databricks
          * Deeplake
          * Docarray
          * Duckdb
          * Dynamodb
          * Elasticsearch
          * Epsilla
          * Faiss
          * Firestore
          * Google
          * Hologres
          * Jaguar
          * Kdbai
          * Lancedb
          * Lantern
          * Lindorm
          * Mariadb
          * Metal
          * Milvus
          * Mongodb
          * Myscale
          * Neo4jvector
          * Neptune
          * Nile
          * Objectbox
          * Oceanbase
          * Opensearch
          * Oracledb
          * Pgvecto rs
          * Pinecone
          * Postgres
          * Qdrant
          * Redis
          * Relyt
          * Rocksetdb
          * Simple
          * Singlestoredb
          * None
          * Supabase
          * Tablestore
          * Tair
          * Tencentvectordb
          * Tidbvector
          * Timescalevector
          * Txtai
          * Typesense
          * Upstash
          * Vearch
          * Vertexaivectorsearch
          * Vespa
          * Weaviate
          * Wordlift
          * Zep
   
    * Tools
      Tools
       * Arxiv
       * Azure code interpreter
       * Azure cv
       * Azure speech
       * Azure translate
       * Bing search
       * Box
       * Brave search
       * Cassandra
       * Chatgpt plugin
       * Code interpreter
       * Cogniswitch
       * Database
       * None
       * Duckduckgo
       * Exa
       * Finance
       * Function
       * Google
       * Graphql
       * Ionic shopping
       * Jina
       * Load and search
       * Metaphor
       * Multion
       * Neo4j
       * Notion
       * Ondemand loader
       * Openai
       * Openapi
       * None
       * Passio nutrition ai
       * Playgrounds
       * Python file
       * Query engine
       * Query plan
       * Requests
       * Retriever
       * Salesforce
       * Shopify
       * Slack
       * Tavily research
       * Text to image
       * Tool spec
       * Vectara query
       * Vector db
       * Waii
       * Weather
       * Wikipedia
       * Wolfram alpha
       * Yahoo finance
       * Yelp
       * Zapier
   
    * Workflow
      Workflow
       * Decorators
       * Context
       * Events
       * Retry policy
       * Workflow

 * Open-Source Community
   Open-Source Community
    * Integrations
    * Full Stack Projects
    * Community FAQ
      Community FAQ
       * Chat Engines
       * Documents and Nodes
       * Embeddings
       * Large Language Models
       * Query Engines
       * Vector Database
   
    * Contributing
      Contributing
       * Code
       * Docs
   
    * Changelog
    * Presentations
    * Upgrading to v0.10.x
    * Deprecated Terms

 * LlamaCloud
   LlamaCloud
    * LlamaParse

Table of contents
 * MemgraphGraphStore
    * query
    * get
    * get_rel_map
    * upsert_triplet
    * delete
    * refresh_schema
    * get_schema

 * MemgraphPropertyGraphStore
    * refresh_schema
    * upsert_relations
    * get
    * get_rel_map
    * delete


MEMGRAPH


MEMGRAPHGRAPHSTORE #

Bases: GraphStore

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169

class MemgraphGraphStore(GraphStore):
    def __init__(
        self,
        username: str,
        password: str,
        url: str,
        database: str = "memgraph",
        node_label: str = "Entity",
        **kwargs: Any,
    ) -> None:
        try:
            import neo4j
        except ImportError:
            raise ImportError("Please install neo4j: pip install neo4j")
        self.node_label = node_label
        self._driver = neo4j.GraphDatabase.driver(url, auth=(username, password))
        self._database = database
        self.schema = ""
        # verify connection
        try:
            self._driver.verify_connectivity()
        except neo4j.exceptions.ServiceUnavailable:
            raise ValueError(
                "Could not connect to Memgraph database. "
                "Please ensure that the url is correct"
            )
        except neo4j.exceptions.AuthError:
            raise ValueError(
                "Could not connect to Memgraph database. "
                "Please ensure that the username and password are correct"
            )
        # set schema
        self.refresh_schema()

        # create constraint
        self.query(
            """
            CREATE CONSTRAINT ON (n:%s) ASSERT n.id IS UNIQUE;
            """
            % (self.node_label)
        )

        # create index
        self.query(
            """
            CREATE INDEX ON :%s(id);
            """
            % (self.node_label)
        )

    @property
    def client(self) -> Any:
        return self._driver

    def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
        """Execute a Cypher query."""
        with self._driver.session(database=self._database) as session:
            result = session.run(query, param_map)
            return [record.data() for record in result]

    def get(self, subj: str) -> List[List[str]]:
        """Get triplets."""
        query = f"""
            MATCH (n1:{self.node_label})-[r]->(n2:{self.node_label})
            WHERE n1.id = $subj
            RETURN type(r), n2.id;
        """

        with self._driver.session(database=self._database) as session:
            data = session.run(query, {"subj": subj})
            return [record.values() for record in data]

    def get_rel_map(
        self, subjs: Optional[List[str]] = None, depth: int = 2
    ) -> Dict[str, List[List[str]]]:
        """Get flat relation map."""
        rel_map: Dict[Any, List[Any]] = {}
        if subjs is None or len(subjs) == 0:
            return rel_map

        query = (
            f"""MATCH p=(n1:{self.node_label})-[*1..{depth}]->() """
            f"""{"WHERE n1.id IN $subjs" if subjs else ""} """
            "UNWIND relationships(p) AS rel "
            "WITH n1.id AS subj, collect([type(rel), endNode(rel).id]) AS rels "
            "RETURN subj, rels"
        )

        data = list(self.query(query, {"subjs": subjs}))
        if not data:
            return rel_map

        for record in data:
            rel_map[record["subj"]] = record["rels"]

        return rel_map

    def upsert_triplet(self, subj: str, rel: str, obj: str) -> None:
        """Add triplet."""
        query = f"""
            MERGE (n1:`{self.node_label}` {{id:$subj}})
            MERGE (n2:`{self.node_label}` {{id:$obj}})
            MERGE (n1)-[:`{rel.replace(" ", "_").upper()}`]->(n2)
        """
        self.query(query, {"subj": subj, "obj": obj})

    def delete(self, subj: str, rel: str, obj: str) -> None:
        """Delete triplet."""
        query = f"""
            MATCH (n1:`{self.node_label}`)-[r:`{rel}`]->(n2:`{self.node_label}`)
            WHERE n1.id = $subj AND n2.id = $obj
            DELETE r
        """
        self.query(query, {"subj": subj, "obj": obj})

    def refresh_schema(self) -> None:
        """
        Refreshes the Memgraph graph schema information.
        """
        node_properties = self.query(node_properties_query)
        relationships_properties = self.query(rel_properties_query)
        relationships = self.query(rel_query)

        self.schema = f"""
        Node properties are the following:
        {node_properties}
        Relationship properties are the following:
        {relationships_properties}
        The relationships are the following:
        {relationships}
        """

    def get_schema(self, refresh: bool = False) -> str:
        """Get the schema of the MemgraphGraph store."""
        if self.schema and not refresh:
            return self.schema
        self.refresh_schema()
        logger.debug(f"get_schema() schema:\n{self.schema}")
        return self.schema



QUERY #

query(query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any


Execute a Cypher query.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

85
86
87
88
89

def query(self, query: str, param_map: Optional[Dict[str, Any]] = {}) -> Any:
    """Execute a Cypher query."""
    with self._driver.session(database=self._database) as session:
        result = session.run(query, param_map)
        return [record.data() for record in result]



GET #

get(subj: str) -> List[List[str]]


Get triplets.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101

def get(self, subj: str) -> List[List[str]]:
    """Get triplets."""
    query = f"""
        MATCH (n1:{self.node_label})-[r]->(n2:{self.node_label})
        WHERE n1.id = $subj
        RETURN type(r), n2.id;
    """

    with self._driver.session(database=self._database) as session:
        data = session.run(query, {"subj": subj})
        return [record.values() for record in data]



GET_REL_MAP #

get_rel_map(subjs: Optional[List[str]] = None, depth: int = 2) -> Dict[str, List[List[str]]]


Get flat relation map.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126

def get_rel_map(
    self, subjs: Optional[List[str]] = None, depth: int = 2
) -> Dict[str, List[List[str]]]:
    """Get flat relation map."""
    rel_map: Dict[Any, List[Any]] = {}
    if subjs is None or len(subjs) == 0:
        return rel_map

    query = (
        f"""MATCH p=(n1:{self.node_label})-[*1..{depth}]->() """
        f"""{"WHERE n1.id IN $subjs" if subjs else ""} """
        "UNWIND relationships(p) AS rel "
        "WITH n1.id AS subj, collect([type(rel), endNode(rel).id]) AS rels "
        "RETURN subj, rels"
    )

    data = list(self.query(query, {"subjs": subjs}))
    if not data:
        return rel_map

    for record in data:
        rel_map[record["subj"]] = record["rels"]

    return rel_map



UPSERT_TRIPLET #

upsert_triplet(subj: str, rel: str, obj: str) -> None


Add triplet.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

128
129
130
131
132
133
134
135

def upsert_triplet(self, subj: str, rel: str, obj: str) -> None:
    """Add triplet."""
    query = f"""
        MERGE (n1:`{self.node_label}` {{id:$subj}})
        MERGE (n2:`{self.node_label}` {{id:$obj}})
        MERGE (n1)-[:`{rel.replace(" ", "_").upper()}`]->(n2)
    """
    self.query(query, {"subj": subj, "obj": obj})



DELETE #

delete(subj: str, rel: str, obj: str) -> None


Delete triplet.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

137
138
139
140
141
142
143
144

def delete(self, subj: str, rel: str, obj: str) -> None:
    """Delete triplet."""
    query = f"""
        MATCH (n1:`{self.node_label}`)-[r:`{rel}`]->(n2:`{self.node_label}`)
        WHERE n1.id = $subj AND n2.id = $obj
        DELETE r
    """
    self.query(query, {"subj": subj, "obj": obj})



REFRESH_SCHEMA #

refresh_schema() -> None


Refreshes the Memgraph graph schema information.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161

def refresh_schema(self) -> None:
    """
    Refreshes the Memgraph graph schema information.
    """
    node_properties = self.query(node_properties_query)
    relationships_properties = self.query(rel_properties_query)
    relationships = self.query(rel_query)

    self.schema = f"""
    Node properties are the following:
    {node_properties}
    Relationship properties are the following:
    {relationships_properties}
    The relationships are the following:
    {relationships}
    """



GET_SCHEMA #

get_schema(refresh: bool = False) -> str


Get the schema of the MemgraphGraph store.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/kg_base.py

163
164
165
166
167
168
169

def get_schema(self, refresh: bool = False) -> str:
    """Get the schema of the MemgraphGraph store."""
    if self.schema and not refresh:
        return self.schema
    self.refresh_schema()
    logger.debug(f"get_schema() schema:\n{self.schema}")
    return self.schema



MEMGRAPHPROPERTYGRAPHSTORE #

Bases: PropertyGraphStore

Memgraph Property Graph Store.

This class implements a Memgraph property graph store.

Parameters:

Name Type Description Default username str

The username for the Memgraph database.

required password str

The password for the Memgraph database.

required url str

The URL for the Memgraph database.

required database Optional[str]

The name of the database to connect to. Defaults to "memgraph".

'memgraph'

Examples:

from llama_index.core.indices.property_graph import PropertyGraphIndex
from llama_index.graph_stores.memgraph import MemgraphPropertyGraphStore

# Create a MemgraphPropertyGraphStore instance
graph_store = MemgraphPropertyGraphStore(
    username="memgraph",
    password="password",
    url="bolt://localhost:7687",
    database="memgraph"
)

# Create the index
index = PropertyGraphIndex.from_documents(
    documents,
    property_graph_store=graph_store,
)

# Close the Memgraph connection explicitly.
graph_store.close()


Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/property_graph.py

 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962

class MemgraphPropertyGraphStore(PropertyGraphStore):
    r"""
    Memgraph Property Graph Store.

    This class implements a Memgraph property graph store.

    Args:
        username (str): The username for the Memgraph database.
        password (str): The password for the Memgraph database.
        url (str): The URL for the Memgraph database.
        database (Optional[str]): The name of the database to connect to. Defaults to "memgraph".

    Examples:
        ```python
        from llama_index.core.indices.property_graph import PropertyGraphIndex
        from llama_index.graph_stores.memgraph import MemgraphPropertyGraphStore

        # Create a MemgraphPropertyGraphStore instance
        graph_store = MemgraphPropertyGraphStore(
            username="memgraph",
            password="password",
            url="bolt://localhost:7687",
            database="memgraph"
        )

        # Create the index
        index = PropertyGraphIndex.from_documents(
            documents,
            property_graph_store=graph_store,
        )

        # Close the Memgraph connection explicitly.
        graph_store.close()
        ```
    """

    supports_structured_queries: bool = True
    text_to_cypher_template: PromptTemplate = DEFAULT_CYPHER_TEMPALTE

    def __init__(
        self,
        username: str,
        password: str,
        url: str,
        database: Optional[str] = "memgraph",
        refresh_schema: bool = True,
        sanitize_query_output: bool = True,
        enhanced_schema: bool = False,
        **neo4j_kwargs: Any,
    ) -> None:
        self.sanitize_query_output = sanitize_query_output
        self.enhanced_schema = enhanced_schema
        self._driver = neo4j.GraphDatabase.driver(
            url, auth=(username, password), **neo4j_kwargs
        )
        self._database = database
        self.structured_schema = {}
        if refresh_schema:
            self.refresh_schema()

        # Create index for faster imports and retrieval
        self.structured_query(f"""CREATE INDEX ON :{BASE_NODE_LABEL}(id);""")
        self.structured_query(f"""CREATE INDEX ON :{BASE_ENTITY_LABEL}(id);""")

    @property
    def client(self):
        return self._driver

    def close(self) -> None:
        self._driver.close()

    def refresh_schema(self) -> None:
        """Refresh the schema."""
        # Leave schema empty if db is empty
        if self.structured_query("MATCH (n) RETURN n LIMIT 1") == []:
            return

        node_query_results = self.structured_query(
            node_properties_query,
            param_map={
                "EXCLUDED_LABELS": [
                    *EXCLUDED_LABELS,
                    BASE_ENTITY_LABEL,
                    BASE_NODE_LABEL,
                ]
            },
        )
        node_properties = {}
        for el in node_query_results:
            if el["output"]["labels"] in [
                *EXCLUDED_LABELS,
                BASE_ENTITY_LABEL,
                BASE_NODE_LABEL,
            ]:
                continue

            label = el["output"]["labels"]
            properties = el["output"]["properties"]
            if label in node_properties:
                node_properties[label]["properties"].extend(
                    prop
                    for prop in properties
                    if prop not in node_properties[label]["properties"]
                )
            else:
                node_properties[label] = {"properties": properties}

        node_properties = [
            {"labels": label, **value} for label, value in node_properties.items()
        ]
        rels_query_result = self.structured_query(
            rel_properties_query, param_map={"EXCLUDED_LABELS": EXCLUDED_RELS}
        )
        rel_properties = (
            [
                el["output"]
                for el in rels_query_result
                if any(prop["property"] for prop in el["output"].get("properties", []))
            ]
            if rels_query_result
            else []
        )
        rel_objs_query_result = self.structured_query(
            rel_query,
            param_map={
                "EXCLUDED_LABELS": [
                    *EXCLUDED_LABELS,
                    BASE_ENTITY_LABEL,
                    BASE_NODE_LABEL,
                ]
            },
        )
        relationships = [
            el["output"]
            for el in rel_objs_query_result
            if rel_objs_query_result
            and el["output"]["start"]
            not in [*EXCLUDED_LABELS, BASE_ENTITY_LABEL, BASE_NODE_LABEL]
            and el["output"]["end"]
            not in [*EXCLUDED_LABELS, BASE_ENTITY_LABEL, BASE_NODE_LABEL]
        ]
        self.structured_schema = {
            "node_props": {el["labels"]: el["properties"] for el in node_properties},
            "rel_props": {el["type"]: el["properties"] for el in rel_properties},
            "relationships": relationships,
        }
        schema_nodes = self.structured_query(
            "MATCH (n) UNWIND labels(n) AS label RETURN label AS node, COUNT(n) AS count ORDER BY count DESC"
        )
        schema_rels = self.structured_query(
            "MATCH ()-[r]->() RETURN TYPE(r) AS relationship_type, COUNT(r) AS count"
        )
        schema_counts = [
            {
                "nodes": [
                    {"name": item["node"], "count": item["count"]}
                    for item in schema_nodes
                ],
                "relationships": [
                    {"name": item["relationship_type"], "count": item["count"]}
                    for item in schema_rels
                ],
            }
        ]
        # Update node info
        for node in schema_counts[0].get("nodes", []):
            # Skip bloom labels
            if node["name"] in EXCLUDED_LABELS:
                continue
            node_props = self.structured_schema["node_props"].get(node["name"])
            if not node_props:  # The node has no properties
                continue

            enhanced_cypher = self._enhanced_schema_cypher(
                node["name"], node_props, node["count"] < EXHAUSTIVE_SEARCH_LIMIT
            )
            output = self.structured_query(enhanced_cypher)
            enhanced_info = output[0]["output"]
            for prop in node_props:
                if prop["property"] in enhanced_info:
                    prop.update(enhanced_info[prop["property"]])

        # Update rel info
        for rel in schema_counts[0].get("relationships", []):
            if rel["name"] in EXCLUDED_RELS:
                continue
            rel_props = self.structured_schema["rel_props"].get(f":`{rel['name']}`")
            if not rel_props:  # The rel has no properties
                continue
            enhanced_cypher = self._enhanced_schema_cypher(
                rel["name"],
                rel_props,
                rel["count"] < EXHAUSTIVE_SEARCH_LIMIT,
                is_relationship=True,
            )
            try:
                enhanced_info = self.structured_query(enhanced_cypher)[0]["output"]
                for prop in rel_props:
                    if prop["property"] in enhanced_info:
                        prop.update(enhanced_info[prop["property"]])
            except neo4j.exceptions.ClientError:
                pass

    def upsert_nodes(self, nodes: List[LabelledNode]) -> None:
        # Lists to hold separated types
        entity_dicts: List[dict] = []
        chunk_dicts: List[dict] = []

        # Sort by type
        for item in nodes:
            if isinstance(item, EntityNode):
                entity_dicts.append({**item.dict(), "id": item.id})
            elif isinstance(item, ChunkNode):
                chunk_dicts.append({**item.dict(), "id": item.id})
            else:
                pass
        if chunk_dicts:
            for index in range(0, len(chunk_dicts), CHUNK_SIZE):
                chunked_params = chunk_dicts[index : index + CHUNK_SIZE]
                for param in chunked_params:
                    formatted_properties = ", ".join(
                        [
                            f"{key}: {value!r}"
                            for key, value in param["properties"].items()
                        ]
                    )
                    self.structured_query(
                        f"""
                        MERGE (c:{BASE_NODE_LABEL} {{id: '{param["id"]}'}})
                        SET c.`text` = '{param["text"]}', c:Chunk
                        WITH c
                        SET c += {{{formatted_properties}}}
                        RETURN count(*)
                        """
                    )
        if entity_dicts:
            for index in range(0, len(entity_dicts), CHUNK_SIZE):
                chunked_params = entity_dicts[index : index + CHUNK_SIZE]
                for param in chunked_params:
                    formatted_properties = ", ".join(
                        [
                            f"{key}: {value!r}"
                            for key, value in param["properties"].items()
                        ]
                    )
                    self.structured_query(
                        f"""
                        MERGE (e:{BASE_NODE_LABEL} {{id: '{param["id"]}'}})
                        SET e += {{{formatted_properties}}}
                        SET e.name = '{param["name"]}', e:`{BASE_ENTITY_LABEL}`
                        WITH e
                        SET e :{param["label"]}
                        """
                    )
                    triplet_source_id = param["properties"].get("triplet_source_id")
                    if triplet_source_id:
                        self.structured_query(
                            f"""
                            MERGE (e:{BASE_NODE_LABEL} {{id: '{param["id"]}'}})
                            MERGE (c:{BASE_NODE_LABEL} {{id: '{triplet_source_id}'}})
                            MERGE (e)<-[:MENTIONS]-(c)
                            """
                        )

    def upsert_relations(self, relations: List[Relation]) -> None:
        """Add relations."""
        params = [r.dict() for r in relations]
        for index in range(0, len(params), CHUNK_SIZE):
            chunked_params = params[index : index + CHUNK_SIZE]
            for param in chunked_params:
                formatted_properties = ", ".join(
                    [f"{key}: {value!r}" for key, value in param["properties"].items()]
                )

                self.structured_query(
                    f"""
                    MERGE (source: {BASE_NODE_LABEL} {{id: '{param["source_id"]}'}})
                    ON CREATE SET source:Chunk
                    MERGE (target: {BASE_NODE_LABEL} {{id: '{param["target_id"]}'}})
                    ON CREATE SET target:Chunk
                    WITH source, target
                    MERGE (source)-[r:{param["label"]}]->(target)
                    SET r += {{{formatted_properties}}}
                    RETURN count(*)
                    """
                )

    def get(
        self,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> List[LabelledNode]:
        """Get nodes."""
        cypher_statement = f"MATCH (e:{BASE_NODE_LABEL}) "

        params = {}
        cypher_statement += "WHERE e.id IS NOT NULL "

        if ids:
            cypher_statement += "AND e.id IN $ids "
            params["ids"] = ids

        if properties:
            prop_list = []
            for i, prop in enumerate(properties):
                prop_list.append(f"e.`{prop}` = $property_{i}")
                params[f"property_{i}"] = properties[prop]
            cypher_statement += " AND " + " AND ".join(prop_list)

        return_statement = """
            RETURN
            e.id AS name,
            CASE
                WHEN labels(e)[0] IN ['__Entity__', '__Node__'] THEN
                    CASE
                        WHEN size(labels(e)) > 2 THEN labels(e)[2]
                        WHEN size(labels(e)) > 1 THEN labels(e)[1]
                        ELSE NULL
                    END
                ELSE labels(e)[0]
            END AS type,
            properties(e) AS properties
        """
        cypher_statement += return_statement
        response = self.structured_query(cypher_statement, param_map=params)
        response = response if response else []

        nodes = []
        for record in response:
            if "text" in record["properties"] or record["type"] is None:
                text = record["properties"].pop("text", "")
                nodes.append(
                    ChunkNode(
                        id_=record["name"],
                        text=text,
                        properties=remove_empty_values(record["properties"]),
                    )
                )
            else:
                nodes.append(
                    EntityNode(
                        name=record["name"],
                        label=record["type"],
                        properties=remove_empty_values(record["properties"]),
                    )
                )

        return nodes

    def get_triplets(
        self,
        entity_names: Optional[List[str]] = None,
        relation_names: Optional[List[str]] = None,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> List[Triplet]:
        cypher_statement = f"MATCH (e:`{BASE_ENTITY_LABEL}`)-[r]->(t) "

        params = {}
        if entity_names or relation_names or properties or ids:
            cypher_statement += "WHERE "

        if entity_names:
            cypher_statement += "e.name in $entity_names "
            params["entity_names"] = entity_names

        if relation_names and entity_names:
            cypher_statement += f"AND "

        if relation_names:
            cypher_statement += "type(r) in $relation_names "
            params[f"relation_names"] = relation_names

        if ids:
            cypher_statement += "e.id in $ids "
            params["ids"] = ids

        if properties:
            prop_list = []
            for i, prop in enumerate(properties):
                prop_list.append(f"e.`{prop}` = $property_{i}")
                params[f"property_{i}"] = properties[prop]
            cypher_statement += " AND ".join(prop_list)

        if not (entity_names or properties or relation_names or ids):
            return_statement = """
                WHERE NOT ANY(label IN labels(e) WHERE label = 'Chunk')
                RETURN type(r) as type, properties(r) as rel_prop, e.id as source_id,
                CASE
                    WHEN labels(e)[0] IN ['__Entity__', '__Node__'] THEN
                        CASE
                            WHEN size(labels(e)) > 2 THEN labels(e)[2]
                            WHEN size(labels(e)) > 1 THEN labels(e)[1]
                            ELSE NULL
                        END
                    ELSE labels(e)[0]
                END AS source_type,
                properties(e) AS source_properties,
                t.id as target_id,
                CASE
                    WHEN labels(t)[0] IN ['__Entity__', '__Node__'] THEN
                        CASE
                            WHEN size(labels(t)) > 2 THEN labels(t)[2]
                            WHEN size(labels(t)) > 1 THEN labels(t)[1]
                            ELSE NULL
                        END
                    ELSE labels(t)[0]
                END AS target_type, properties(t) AS target_properties LIMIT 100;
            """
        else:
            return_statement = """
            AND NOT ANY(label IN labels(e) WHERE label = 'Chunk')
                RETURN type(r) as type, properties(r) as rel_prop, e.id as source_id,
                CASE
                    WHEN labels(e)[0] IN ['__Entity__', '__Node__'] THEN
                        CASE
                            WHEN size(labels(e)) > 2 THEN labels(e)[2]
                            WHEN size(labels(e)) > 1 THEN labels(e)[1]
                            ELSE NULL
                        END
                    ELSE labels(e)[0]
                END AS source_type,
                properties(e) AS source_properties,
                t.id as target_id,
                CASE
                    WHEN labels(t)[0] IN ['__Entity__', '__Node__'] THEN
                        CASE
                            WHEN size(labels(t)) > 2 THEN labels(t)[2]
                            WHEN size(labels(t)) > 1 THEN labels(t)[1]
                            ELSE NULL
                        END
                    ELSE labels(t)[0]
                END AS target_type, properties(t) AS target_properties LIMIT 100;
            """

        cypher_statement += return_statement
        data = self.structured_query(cypher_statement, param_map=params)
        data = data if data else []

        triplets = []
        for record in data:
            source = EntityNode(
                name=record["source_id"],
                label=record["source_type"],
                properties=remove_empty_values(record["source_properties"]),
            )
            target = EntityNode(
                name=record["target_id"],
                label=record["target_type"],
                properties=remove_empty_values(record["target_properties"]),
            )
            rel = Relation(
                source_id=record["source_id"],
                target_id=record["target_id"],
                label=record["type"],
                properties=remove_empty_values(record["rel_prop"]),
            )
            triplets.append([source, rel, target])
        return triplets

    def get_rel_map(
        self,
        graph_nodes: List[LabelledNode],
        depth: int = 2,
        limit: int = 30,
        ignore_rels: Optional[List[str]] = None,
    ) -> List[Triplet]:
        """Get depth-aware rel map."""
        triples = []

        ids = [node.id for node in graph_nodes]
        response = self.structured_query(
            f"""
            WITH $ids AS id_list
            UNWIND range(0, size(id_list) - 1) AS idx
            MATCH (e:__Node__)
            WHERE e.id = id_list[idx]
            MATCH p=(e)-[r*1..{depth}]-(other)
            WHERE ALL(rel in relationships(p) WHERE type(rel) <> 'MENTIONS')
            UNWIND relationships(p) AS rel
            WITH DISTINCT rel, idx
            WITH startNode(rel) AS source,
                type(rel) AS type,
                rel{{.*}} AS rel_properties,
                endNode(rel) AS endNode,
                idx
            LIMIT toInteger($limit)
            RETURN source.id AS source_id,
                CASE
                    WHEN labels(source)[0] IN ['__Entity__', '__Node__'] THEN
                        CASE
                            WHEN size(labels(source)) > 2 THEN labels(source)[2]
                            WHEN size(labels(source)) > 1 THEN labels(source)[1]
                            ELSE NULL
                        END
                    ELSE labels(source)[0]
                END AS source_type,
                properties(source) AS source_properties,
                type,
                rel_properties,
                endNode.id AS target_id,
                CASE
                    WHEN labels(endNode)[0] IN ['__Entity__', '__Node__'] THEN
                        CASE
                            WHEN size(labels(endNode)) > 2 THEN labels(endNode)[2]
                            WHEN size(labels(endNode)) > 1 THEN labels(endNode)[1] ELSE NULL
                        END
                    ELSE labels(endNode)[0]
                END AS target_type,
                properties(endNode) AS target_properties,
                idx
            ORDER BY idx
            LIMIT toInteger($limit)
            """,
            param_map={"ids": ids, "limit": limit},
        )
        response = response if response else []

        ignore_rels = ignore_rels or []
        for record in response:
            if record["type"] in ignore_rels:
                continue

            source = EntityNode(
                name=record["source_id"],
                label=record["source_type"],
                properties=remove_empty_values(record["source_properties"]),
            )
            target = EntityNode(
                name=record["target_id"],
                label=record["target_type"],
                properties=remove_empty_values(record["target_properties"]),
            )
            rel = Relation(
                source_id=record["source_id"],
                target_id=record["target_id"],
                label=record["type"],
                properties=remove_empty_values(record["rel_properties"]),
            )
            triples.append([source, rel, target])

        return triples

    def structured_query(
        self, query: str, param_map: Optional[Dict[str, Any]] = None
    ) -> Any:
        param_map = param_map or {}

        with self._driver.session(database=self._database) as session:
            result = session.run(query, param_map)
            full_result = [d.data() for d in result]

        if self.sanitize_query_output:
            return [value_sanitize(el) for el in full_result]
        return full_result

    def vector_query(
        self, query: VectorStoreQuery, **kwargs: Any
    ) -> Tuple[List[LabelledNode], List[float]]:
        raise NotImplementedError(
            "Vector query is not currently implemented for MemgraphPropertyGraphStore."
        )

    def delete(
        self,
        entity_names: Optional[List[str]] = None,
        relation_names: Optional[List[str]] = None,
        properties: Optional[dict] = None,
        ids: Optional[List[str]] = None,
    ) -> None:
        """Delete matching data."""
        if entity_names:
            self.structured_query(
                "MATCH (n) WHERE n.name IN $entity_names DETACH DELETE n",
                param_map={"entity_names": entity_names},
            )
        if ids:
            self.structured_query(
                "MATCH (n) WHERE n.id IN $ids DETACH DELETE n",
                param_map={"ids": ids},
            )
        if relation_names:
            for rel in relation_names:
                self.structured_query(f"MATCH ()-[r:`{rel}`]->() DELETE r")

        if properties:
            cypher = "MATCH (e) WHERE "
            prop_list = []
            params = {}
            for i, prop in enumerate(properties):
                prop_list.append(f"e.`{prop}` = $property_{i}")
                params[f"property_{i}"] = properties[prop]
            cypher += " AND ".join(prop_list)
            self.structured_query(cypher + " DETACH DELETE e", param_map=params)

    def _enhanced_schema_cypher(
        self,
        label_or_type: str,
        properties: List[Dict[str, Any]],
        exhaustive: bool,
        is_relationship: bool = False,
    ) -> str:
        if is_relationship:
            match_clause = f"MATCH ()-[n:`{label_or_type}`]->()"
        else:
            match_clause = f"MATCH (n:`{label_or_type}`)"

        with_clauses = []
        return_clauses = []
        output_dict = {}
        if exhaustive:
            for prop in properties:
                if prop["property"]:
                    prop_name = prop["property"]
                else:
                    prop_name = None
                if prop["type"]:
                    prop_type = prop["type"]
                else:
                    prop_type = None
                if prop_type == "String":
                    with_clauses.append(
                        f"collect(distinct substring(toString(n.`{prop_name}`), 0, 50)) "
                        f"AS `{prop_name}_values`"
                    )
                    return_clauses.append(
                        f"values:`{prop_name}_values`[..{DISTINCT_VALUE_LIMIT}],"
                        f" distinct_count: size(`{prop_name}_values`)"
                    )
                elif prop_type in [
                    "Int",
                    "Double",
                    "Date",
                    "LocalTime",
                    "LocalDateTime",
                ]:
                    with_clauses.append(f"min(n.`{prop_name}`) AS `{prop_name}_min`")
                    with_clauses.append(f"max(n.`{prop_name}`) AS `{prop_name}_max`")
                    with_clauses.append(
                        f"count(distinct n.`{prop_name}`) AS `{prop_name}_distinct`"
                    )
                    return_clauses.append(
                        f"min: toString(`{prop_name}_min`), "
                        f"max: toString(`{prop_name}_max`), "
                        f"distinct_count: `{prop_name}_distinct`"
                    )
                elif prop_type in ["List", "List[Any]"]:
                    with_clauses.append(
                        f"min(size(n.`{prop_name}`)) AS `{prop_name}_size_min`, "
                        f"max(size(n.`{prop_name}`)) AS `{prop_name}_size_max`"
                    )
                    return_clauses.append(
                        f"min_size: `{prop_name}_size_min`, "
                        f"max_size: `{prop_name}_size_max`"
                    )
                elif prop_type in ["Bool", "Duration"]:
                    continue
                if return_clauses:
                    output_dict[prop_name] = "{" + return_clauses.pop() + "}"
                else:
                    output_dict[prop_name] = None
        else:
            # Just sample 5 random nodes
            match_clause += " WITH n LIMIT 5"
            for prop in properties:
                prop_name = prop["property"]
                prop_type = prop["type"]

                # Check if indexed property, we can still do exhaustive
                prop_index = [
                    el
                    for el in self.structured_schema["metadata"]["index"]
                    if el["label"] == label_or_type
                    and el["properties"] == [prop_name]
                    and el["type"] == "RANGE"
                ]
                if prop_type == "String":
                    if (
                        prop_index
                        and prop_index[0].get("size") > 0
                        and prop_index[0].get("distinctValues") <= DISTINCT_VALUE_LIMIT
                    ):
                        distinct_values_query = f"""
                            MATCH (n:{label_or_type})
                            RETURN DISTINCT n.`{prop_name}` AS value
                            LIMIT {DISTINCT_VALUE_LIMIT}
                        """
                        distinct_values = self.query(distinct_values_query)

                        # Extract values from the result set
                        distinct_values = [
                            record["value"] for record in distinct_values
                        ]

                        return_clauses.append(
                            f"values: {distinct_values},"
                            f" distinct_count: {len(distinct_values)}"
                        )
                    else:
                        with_clauses.append(
                            f"collect(distinct substring(n.`{prop_name}`, 0, 50)) "
                            f"AS `{prop_name}_values`"
                        )
                        return_clauses.append(f"values: `{prop_name}_values`")
                elif prop_type in [
                    "Int",
                    "Double",
                    "Float",
                    "Date",
                    "LocalTime",
                    "LocalDateTime",
                ]:
                    if not prop_index:
                        with_clauses.append(
                            f"collect(distinct toString(n.`{prop_name}`)) "
                            f"AS `{prop_name}_values`"
                        )
                        return_clauses.append(f"values: `{prop_name}_values`")
                    else:
                        with_clauses.append(
                            f"min(n.`{prop_name}`) AS `{prop_name}_min`"
                        )
                        with_clauses.append(
                            f"max(n.`{prop_name}`) AS `{prop_name}_max`"
                        )
                        with_clauses.append(
                            f"count(distinct n.`{prop_name}`) AS `{prop_name}_distinct`"
                        )
                        return_clauses.append(
                            f"min: toString(`{prop_name}_min`), "
                            f"max: toString(`{prop_name}_max`), "
                            f"distinct_count: `{prop_name}_distinct`"
                        )

                elif prop_type in ["List", "List[Any]"]:
                    with_clauses.append(
                        f"min(size(n.`{prop_name}`)) AS `{prop_name}_size_min`, "
                        f"max(size(n.`{prop_name}`)) AS `{prop_name}_size_max`"
                    )
                    return_clauses.append(
                        f"min_size: `{prop_name}_size_min`, "
                        f"max_size: `{prop_name}_size_max`"
                    )
                elif prop_type in ["Bool", "Duration"]:
                    continue
                if return_clauses:
                    output_dict[prop_name] = "{" + return_clauses.pop() + "}"
                else:
                    output_dict[prop_name] = None

        with_clause = "WITH " + ",\n     ".join(with_clauses)
        return_clause = (
            "RETURN {"
            + ", ".join(f"`{k}`: {v}" for k, v in output_dict.items())
            + "} AS output"
        )
        # Combine all parts of the Cypher query
        return f"{match_clause}\n{with_clause}\n{return_clause}"

    def get_schema(self, refresh: bool = False) -> Any:
        if refresh:
            self.refresh_schema()

        return self.structured_schema

    def get_schema_str(self, refresh: bool = False) -> str:
        schema = self.get_schema(refresh=refresh)

        formatted_node_props = []
        formatted_rel_props = []

        if self.enhanced_schema:
            # Enhanced formatting for nodes
            for node_type, properties in schema["node_props"].items():
                formatted_node_props.append(f"- **{node_type}**")
                for prop in properties:
                    example = ""
                    if prop["type"] == "String" and prop.get("values"):
                        if prop.get("distinct_count", 11) > DISTINCT_VALUE_LIMIT:
                            example = (
                                f'Example: "{clean_string_values(prop["values"][0])}"'
                                if prop["values"]
                                else ""
                            )
                        else:  # If less than 10 possible values return all
                            example = (
                                (
                                    "Available options: "
                                    f'{[clean_string_values(el) for el in prop["values"]]}'
                                )
                                if prop["values"]
                                else ""
                            )

                    elif prop["type"] in [
                        "Int",
                        "Double",
                        "Float",
                        "Date",
                        "LocalTime",
                        "LocalDateTime",
                    ]:
                        if prop.get("min") is not None:
                            example = f'Min: {prop["min"]}, Max: {prop["max"]}'
                        else:
                            example = (
                                f'Example: "{prop["values"][0]}"'
                                if prop.get("values")
                                else ""
                            )
                    elif prop["type"] in ["List", "List[Any]"]:
                        # Skip embeddings
                        if not prop.get("min_size") or prop["min_size"] > LIST_LIMIT:
                            continue
                        example = f'Min Size: {prop["min_size"]}, Max Size: {prop["max_size"]}'
                    formatted_node_props.append(
                        f"  - `{prop['property']}`: {prop['type']} {example}"
                    )

            # Enhanced formatting for relationships
            for rel_type, properties in schema["rel_props"].items():
                formatted_rel_props.append(f"- **{rel_type}**")
                for prop in properties:
                    example = ""
                    if prop["type"] == "STRING":
                        if prop.get("distinct_count", 11) > DISTINCT_VALUE_LIMIT:
                            example = (
                                f'Example: "{clean_string_values(prop["values"][0])}"'
                                if prop.get("values")
                                else ""
                            )
                        else:  # If less than 10 possible values return all
                            example = (
                                (
                                    "Available options: "
                                    f'{[clean_string_values(el) for el in prop["values"]]}'
                                )
                                if prop.get("values")
                                else ""
                            )
                    elif prop["type"] in [
                        "Int",
                        "Double",
                        "Float",
                        "Date",
                        "LocalTime",
                        "LocalDateTime",
                    ]:
                        if prop.get("min"):  # If we have min/max
                            example = f'Min: {prop["min"]}, Max:  {prop["max"]}'
                        else:  # return a single value
                            example = (
                                f'Example: "{prop["values"][0]}"'
                                if prop.get("values")
                                else ""
                            )
                    elif prop["type"] == "List[Any]":
                        # Skip embeddings
                        if prop["min_size"] > LIST_LIMIT:
                            continue
                        example = f'Min Size: {prop["min_size"]}, Max Size: {prop["max_size"]}'
                    formatted_rel_props.append(
                        f"  - `{prop['property']}: {prop['type']}` {example}"
                    )
        else:
            # Format node properties
            for label, props in schema["node_props"].items():
                props_str = ", ".join(
                    [f"{prop['property']}: {prop['type']}" for prop in props]
                )
                formatted_node_props.append(f"{label} {{{props_str}}}")

            # Format relationship properties using structured_schema
            for type, props in schema["rel_props"].items():
                props_str = ", ".join(
                    [f"{prop['property']}: {prop['type']}" for prop in props]
                )
                formatted_rel_props.append(f"{type} {{{props_str}}}")

        # Format relationships
        formatted_rels = [
            f"(:{el['start']})-[:{el['type']}]->(:{el['end']})"
            for el in schema["relationships"]
        ]

        return "\n".join(
            [
                "Node properties:",
                "\n".join(formatted_node_props),
                "Relationship properties:",
                "\n".join(formatted_rel_props),
                "The relationships:",
                "\n".join(formatted_rels),
            ]
        )



REFRESH_SCHEMA #

refresh_schema() -> None


Refresh the schema.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/property_graph.py

139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269

def refresh_schema(self) -> None:
    """Refresh the schema."""
    # Leave schema empty if db is empty
    if self.structured_query("MATCH (n) RETURN n LIMIT 1") == []:
        return

    node_query_results = self.structured_query(
        node_properties_query,
        param_map={
            "EXCLUDED_LABELS": [
                *EXCLUDED_LABELS,
                BASE_ENTITY_LABEL,
                BASE_NODE_LABEL,
            ]
        },
    )
    node_properties = {}
    for el in node_query_results:
        if el["output"]["labels"] in [
            *EXCLUDED_LABELS,
            BASE_ENTITY_LABEL,
            BASE_NODE_LABEL,
        ]:
            continue

        label = el["output"]["labels"]
        properties = el["output"]["properties"]
        if label in node_properties:
            node_properties[label]["properties"].extend(
                prop
                for prop in properties
                if prop not in node_properties[label]["properties"]
            )
        else:
            node_properties[label] = {"properties": properties}

    node_properties = [
        {"labels": label, **value} for label, value in node_properties.items()
    ]
    rels_query_result = self.structured_query(
        rel_properties_query, param_map={"EXCLUDED_LABELS": EXCLUDED_RELS}
    )
    rel_properties = (
        [
            el["output"]
            for el in rels_query_result
            if any(prop["property"] for prop in el["output"].get("properties", []))
        ]
        if rels_query_result
        else []
    )
    rel_objs_query_result = self.structured_query(
        rel_query,
        param_map={
            "EXCLUDED_LABELS": [
                *EXCLUDED_LABELS,
                BASE_ENTITY_LABEL,
                BASE_NODE_LABEL,
            ]
        },
    )
    relationships = [
        el["output"]
        for el in rel_objs_query_result
        if rel_objs_query_result
        and el["output"]["start"]
        not in [*EXCLUDED_LABELS, BASE_ENTITY_LABEL, BASE_NODE_LABEL]
        and el["output"]["end"]
        not in [*EXCLUDED_LABELS, BASE_ENTITY_LABEL, BASE_NODE_LABEL]
    ]
    self.structured_schema = {
        "node_props": {el["labels"]: el["properties"] for el in node_properties},
        "rel_props": {el["type"]: el["properties"] for el in rel_properties},
        "relationships": relationships,
    }
    schema_nodes = self.structured_query(
        "MATCH (n) UNWIND labels(n) AS label RETURN label AS node, COUNT(n) AS count ORDER BY count DESC"
    )
    schema_rels = self.structured_query(
        "MATCH ()-[r]->() RETURN TYPE(r) AS relationship_type, COUNT(r) AS count"
    )
    schema_counts = [
        {
            "nodes": [
                {"name": item["node"], "count": item["count"]}
                for item in schema_nodes
            ],
            "relationships": [
                {"name": item["relationship_type"], "count": item["count"]}
                for item in schema_rels
            ],
        }
    ]
    # Update node info
    for node in schema_counts[0].get("nodes", []):
        # Skip bloom labels
        if node["name"] in EXCLUDED_LABELS:
            continue
        node_props = self.structured_schema["node_props"].get(node["name"])
        if not node_props:  # The node has no properties
            continue

        enhanced_cypher = self._enhanced_schema_cypher(
            node["name"], node_props, node["count"] < EXHAUSTIVE_SEARCH_LIMIT
        )
        output = self.structured_query(enhanced_cypher)
        enhanced_info = output[0]["output"]
        for prop in node_props:
            if prop["property"] in enhanced_info:
                prop.update(enhanced_info[prop["property"]])

    # Update rel info
    for rel in schema_counts[0].get("relationships", []):
        if rel["name"] in EXCLUDED_RELS:
            continue
        rel_props = self.structured_schema["rel_props"].get(f":`{rel['name']}`")
        if not rel_props:  # The rel has no properties
            continue
        enhanced_cypher = self._enhanced_schema_cypher(
            rel["name"],
            rel_props,
            rel["count"] < EXHAUSTIVE_SEARCH_LIMIT,
            is_relationship=True,
        )
        try:
            enhanced_info = self.structured_query(enhanced_cypher)[0]["output"]
            for prop in rel_props:
                if prop["property"] in enhanced_info:
                    prop.update(enhanced_info[prop["property"]])
        except neo4j.exceptions.ClientError:
            pass



UPSERT_RELATIONS #

upsert_relations(relations: List[Relation]) -> None


Add relations.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/property_graph.py

332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353

def upsert_relations(self, relations: List[Relation]) -> None:
    """Add relations."""
    params = [r.dict() for r in relations]
    for index in range(0, len(params), CHUNK_SIZE):
        chunked_params = params[index : index + CHUNK_SIZE]
        for param in chunked_params:
            formatted_properties = ", ".join(
                [f"{key}: {value!r}" for key, value in param["properties"].items()]
            )

            self.structured_query(
                f"""
                MERGE (source: {BASE_NODE_LABEL} {{id: '{param["source_id"]}'}})
                ON CREATE SET source:Chunk
                MERGE (target: {BASE_NODE_LABEL} {{id: '{param["target_id"]}'}})
                ON CREATE SET target:Chunk
                WITH source, target
                MERGE (source)-[r:{param["label"]}]->(target)
                SET r += {{{formatted_properties}}}
                RETURN count(*)
                """
            )



GET #

get(properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> List[LabelledNode]


Get nodes.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/property_graph.py

355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415

def get(
    self,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> List[LabelledNode]:
    """Get nodes."""
    cypher_statement = f"MATCH (e:{BASE_NODE_LABEL}) "

    params = {}
    cypher_statement += "WHERE e.id IS NOT NULL "

    if ids:
        cypher_statement += "AND e.id IN $ids "
        params["ids"] = ids

    if properties:
        prop_list = []
        for i, prop in enumerate(properties):
            prop_list.append(f"e.`{prop}` = $property_{i}")
            params[f"property_{i}"] = properties[prop]
        cypher_statement += " AND " + " AND ".join(prop_list)

    return_statement = """
        RETURN
        e.id AS name,
        CASE
            WHEN labels(e)[0] IN ['__Entity__', '__Node__'] THEN
                CASE
                    WHEN size(labels(e)) > 2 THEN labels(e)[2]
                    WHEN size(labels(e)) > 1 THEN labels(e)[1]
                    ELSE NULL
                END
            ELSE labels(e)[0]
        END AS type,
        properties(e) AS properties
    """
    cypher_statement += return_statement
    response = self.structured_query(cypher_statement, param_map=params)
    response = response if response else []

    nodes = []
    for record in response:
        if "text" in record["properties"] or record["type"] is None:
            text = record["properties"].pop("text", "")
            nodes.append(
                ChunkNode(
                    id_=record["name"],
                    text=text,
                    properties=remove_empty_values(record["properties"]),
                )
            )
        else:
            nodes.append(
                EntityNode(
                    name=record["name"],
                    label=record["type"],
                    properties=remove_empty_values(record["properties"]),
                )
            )

    return nodes



GET_REL_MAP #

get_rel_map(graph_nodes: List[LabelledNode], depth: int = 2, limit: int = 30, ignore_rels: Optional[List[str]] = None) -> List[Triplet]


Get depth-aware rel map.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/property_graph.py

528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609

def get_rel_map(
    self,
    graph_nodes: List[LabelledNode],
    depth: int = 2,
    limit: int = 30,
    ignore_rels: Optional[List[str]] = None,
) -> List[Triplet]:
    """Get depth-aware rel map."""
    triples = []

    ids = [node.id for node in graph_nodes]
    response = self.structured_query(
        f"""
        WITH $ids AS id_list
        UNWIND range(0, size(id_list) - 1) AS idx
        MATCH (e:__Node__)
        WHERE e.id = id_list[idx]
        MATCH p=(e)-[r*1..{depth}]-(other)
        WHERE ALL(rel in relationships(p) WHERE type(rel) <> 'MENTIONS')
        UNWIND relationships(p) AS rel
        WITH DISTINCT rel, idx
        WITH startNode(rel) AS source,
            type(rel) AS type,
            rel{{.*}} AS rel_properties,
            endNode(rel) AS endNode,
            idx
        LIMIT toInteger($limit)
        RETURN source.id AS source_id,
            CASE
                WHEN labels(source)[0] IN ['__Entity__', '__Node__'] THEN
                    CASE
                        WHEN size(labels(source)) > 2 THEN labels(source)[2]
                        WHEN size(labels(source)) > 1 THEN labels(source)[1]
                        ELSE NULL
                    END
                ELSE labels(source)[0]
            END AS source_type,
            properties(source) AS source_properties,
            type,
            rel_properties,
            endNode.id AS target_id,
            CASE
                WHEN labels(endNode)[0] IN ['__Entity__', '__Node__'] THEN
                    CASE
                        WHEN size(labels(endNode)) > 2 THEN labels(endNode)[2]
                        WHEN size(labels(endNode)) > 1 THEN labels(endNode)[1] ELSE NULL
                    END
                ELSE labels(endNode)[0]
            END AS target_type,
            properties(endNode) AS target_properties,
            idx
        ORDER BY idx
        LIMIT toInteger($limit)
        """,
        param_map={"ids": ids, "limit": limit},
    )
    response = response if response else []

    ignore_rels = ignore_rels or []
    for record in response:
        if record["type"] in ignore_rels:
            continue

        source = EntityNode(
            name=record["source_id"],
            label=record["source_type"],
            properties=remove_empty_values(record["source_properties"]),
        )
        target = EntityNode(
            name=record["target_id"],
            label=record["target_type"],
            properties=remove_empty_values(record["target_properties"]),
        )
        rel = Relation(
            source_id=record["source_id"],
            target_id=record["target_id"],
            label=record["type"],
            properties=remove_empty_values(record["rel_properties"]),
        )
        triples.append([source, rel, target])

    return triples



DELETE #

delete(entity_names: Optional[List[str]] = None, relation_names: Optional[List[str]] = None, properties: Optional[dict] = None, ids: Optional[List[str]] = None) -> None


Delete matching data.

Source code in
llama-index-integrations/graph_stores/llama-index-graph-stores-memgraph/llama_index/graph_stores/memgraph/property_graph.py

631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661

def delete(
    self,
    entity_names: Optional[List[str]] = None,
    relation_names: Optional[List[str]] = None,
    properties: Optional[dict] = None,
    ids: Optional[List[str]] = None,
) -> None:
    """Delete matching data."""
    if entity_names:
        self.structured_query(
            "MATCH (n) WHERE n.name IN $entity_names DETACH DELETE n",
            param_map={"entity_names": entity_names},
        )
    if ids:
        self.structured_query(
            "MATCH (n) WHERE n.id IN $ids DETACH DELETE n",
            param_map={"ids": ids},
        )
    if relation_names:
        for rel in relation_names:
            self.structured_query(f"MATCH ()-[r:`{rel}`]->() DELETE r")

    if properties:
        cypher = "MATCH (e) WHERE "
        prop_list = []
        params = {}
        for i, prop in enumerate(properties):
            prop_list.append(f"e.`{prop}` = $property_{i}")
            params[f"property_{i}"] = properties[prop]
        cypher += " AND ".join(prop_list)
        self.structured_query(cypher + " DETACH DELETE e", param_map=params)


Back to top
Previous
Kuzu
Next
Nebula