Skip to main content
Ctrl+K
🦜🔗 LangChain  documentation - Home 🦜🔗 LangChain  documentation - Home
  • Reference
Ctrl+K
Docs
  • GitHub
  • X / Twitter
Ctrl+K
  • Reference
Docs
  • GitHub
  • X / Twitter

Section Navigation

Base packages

  • Core
  • Langchain
  • Text Splitters
  • Community
    • adapters
    • agent_toolkits
    • agents
    • cache
    • callbacks
    • chains
    • chat_loaders
    • chat_message_histories
    • chat_models
    • cross_encoders
    • docstore
    • document_compressors
    • document_loaders
    • document_transformers
    • embeddings
    • example_selectors
    • graph_vectorstores
      • AdjacentNode
      • CassandraGraphVectorStore
      • GLiNERLinkExtractor
      • HierarchyLinkExtractor
      • HtmlInput
      • HtmlLinkExtractor
      • KeybertLinkExtractor
      • LinkExtractor
      • LinkExtractorAdapter
      • LinkExtractorTransformer
      • Link
      • MmrHelper
      • add_links
      • copy_with_links
      • get_links
      • documents_to_networkx
      • render_graphviz
      • GraphVectorStore
      • GraphVectorStoreRetriever
      • Node
      • nodes_to_documents
    • graphs
    • indexes
    • llms
    • memory
    • output_parsers
    • query_constructors
    • retrievers
    • storage
    • tools
    • utilities
    • utils
    • vectorstores
  • Experimental

Integrations

  • AI21
  • Anthropic
  • AstraDB
  • AWS
  • Azure Ai
  • Azure Dynamic Sessions
  • Cerebras
  • Chroma
  • Cohere
  • Deepseek
  • Elasticsearch
  • Exa
  • Fireworks
  • Google Community
  • Google GenAI
  • Google VertexAI
  • Groq
  • Huggingface
  • IBM
  • Milvus
  • MistralAI
  • MongoDB
  • Neo4J
  • Nomic
  • Nvidia Ai Endpoints
  • Ollama
  • OpenAI
  • Perplexity
  • Pinecone
  • Postgres
  • Prompty
  • Qdrant
  • Redis
  • Sema4
  • Snowflake
  • Sqlserver
  • Standard Tests
  • Tavily
  • Together
  • Unstructured
  • Upstage
  • VoyageAI
  • Weaviate
  • XAI
  • LangChain Python API Reference
  • langchain-community: 0.3.23
  • graph_vectorstores
  • Link

Link#

class langchain_community.graph_vectorstores.links.Link(
kind: str,
direction: Literal['in', 'out', 'bidir'],
tag: str,
)[source]#

Beta

This feature is in beta. It is actively being worked on, so the API may change.

A link to/from a tag of a given kind.

Documents in a graph vector store are connected via “links”. Links form a bipartite graph between documents and tags: documents are connected to tags, and tags are connected to other documents. When documents are retrieved from a graph vector store, a pair of documents are connected with a depth of one if both documents are connected to the same tag.

Links have a kind property, used to namespace different tag identifiers. For example a link to a keyword might use kind kw, while a link to a URL might use kind url. This allows the same tag value to be used in different contexts without causing name collisions.

Links are directed. The directionality of links controls how the graph is traversed at retrieval time. For example, given documents A and B, connected by links to tag T:

A to T

B to T

Result

outgoing

incoming

Retrieval traverses from A to B

incoming

incoming

No traversal from A to B

outgoing

incoming

No traversal from A to B

bidir

incoming

Retrieval traverses from A to B

bidir

outgoing

No traversal from A to B

outgoing

bidir

Retrieval traverses from A to B

incoming

bidir

No traversal from A to B

Directed links make it possible to describe relationships such as term references / definitions: term definitions are generally relevant to any documents that use the term, but the full set of documents using a term generally aren’t relevant to the term’s definition.

See also

  • How to use a graph vector store

  • How to link Documents on hyperlinks in HTML

  • How to link Documents on common keywords (using KeyBERT)

  • How to link Documents on common named entities (using GliNER)

How to add links to a Document#

How to create links#

You can create links using the Link class’s constructors incoming(), outgoing(), and bidir():

from langchain_community.graph_vectorstores.links import Link

print(Link.bidir(kind="location", tag="Paris"))
Link(kind='location', direction='bidir', tag='Paris')

Extending documents with links#

Now that we know how to create links, let’s associate them with some documents. These edges will strengthen the connection between documents that share a keyword when using a graph vector store to retrieve documents.

First, we’ll load some text and chunk it into smaller pieces. Then we’ll add a link to each document to link them all together:

from langchain_community.document_loaders import TextLoader
from langchain_community.graph_vectorstores.links import add_links
from langchain_text_splitters import CharacterTextSplitter

loader = TextLoader("state_of_the_union.txt")

raw_documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
documents = text_splitter.split_documents(raw_documents)

for doc in documents:
    add_links(doc, Link.bidir(kind="genre", tag="oratory"))

print(documents[0].metadata)
{'source': 'state_of_the_union.txt', 'links': [Link(kind='genre', direction='bidir', tag='oratory')]}

As we can see, each document’s metadata now includes a bidirectional link to the genre oratory.

The documents can then be added to a graph vector store:

from langchain_community.graph_vectorstores import CassandraGraphVectorStore

graph_vectorstore = CassandraGraphVectorStore.from_documents(
    documents=documents, embeddings=...
)

Attributes

Methods

__init__(kind, direction, tag)

bidir(kind, tag)

Create a bidirectional link.

incoming(kind, tag)

Create an incoming link.

outgoing(kind, tag)

Create an outgoing link.

__init__(
kind: str,
direction: Literal['in', 'out', 'bidir'],
tag: str,
) → None#
Parameters:
  • kind (str)

  • direction (Literal['in', 'out', 'bidir'])

  • tag (str)

Return type:

None

static bidir(
kind: str,
tag: str,
) → Link[source]#

Create a bidirectional link.

Parameters:
  • kind (str) – the link kind.

  • tag (str) – the link tag.

Return type:

Link

static incoming(
kind: str,
tag: str,
) → Link[source]#

Create an incoming link.

Parameters:
  • kind (str) – the link kind.

  • tag (str) – the link tag.

Return type:

Link

static outgoing(
kind: str,
tag: str,
) → Link[source]#

Create an outgoing link.

Parameters:
  • kind (str) – the link kind.

  • tag (str) – the link tag.

Return type:

Link

Parameters:
  • kind (str)

  • direction (Literal['in', 'out', 'bidir'])

  • tag (str)

On this page
  • Link
    • __init__()
    • bidir()
    • incoming()
    • outgoing()

© Copyright 2025, LangChain Inc.