core,community: add beta decorator to missed GraphVectorStore extensions (#25562)

This commit is contained in:
Erick Friis 2024-08-19 17:29:09 -07:00 committed by GitHub
parent dd2d094adc
commit e01c6789c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 23 additions and 0 deletions

View File

@ -9,6 +9,7 @@ from typing import (
Type, Type,
) )
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
from langchain_core.embeddings import Embeddings from langchain_core.embeddings import Embeddings
from langchain_core.graph_vectorstores.base import ( from langchain_core.graph_vectorstores.base import (
@ -23,6 +24,7 @@ if TYPE_CHECKING:
from cassandra.cluster import Session from cassandra.cluster import Session
@beta()
class CassandraGraphVectorStore(GraphVectorStore): class CassandraGraphVectorStore(GraphVectorStore):
def __init__( def __init__(
self, self,

View File

@ -1,5 +1,6 @@
from typing import Any, Dict, Iterable, List, Optional, Set, Union from typing import Any, Dict, Iterable, List, Optional, Set, Union
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
from langchain_core.graph_vectorstores.links import Link from langchain_core.graph_vectorstores.links import Link
@ -11,6 +12,7 @@ from langchain_community.graph_vectorstores.extractors.link_extractor import (
GLiNERInput = Union[str, Document] GLiNERInput = Union[str, Document]
@beta()
class GLiNERLinkExtractor(LinkExtractor[GLiNERInput]): class GLiNERLinkExtractor(LinkExtractor[GLiNERInput]):
"""Link documents with common named entities using GLiNER <https://github.com/urchade/GLiNER>.""" """Link documents with common named entities using GLiNER <https://github.com/urchade/GLiNER>."""

View File

@ -1,5 +1,6 @@
from typing import Callable, List, Set from typing import Callable, List, Set
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
from langchain_core.graph_vectorstores.links import Link from langchain_core.graph_vectorstores.links import Link
@ -18,6 +19,7 @@ _CHILD: str = "c:"
_SIBLING: str = "s:" _SIBLING: str = "s:"
@beta()
class HierarchyLinkExtractor(LinkExtractor[HierarchyInput]): class HierarchyLinkExtractor(LinkExtractor[HierarchyInput]):
def __init__( def __init__(
self, self,

View File

@ -4,6 +4,7 @@ from dataclasses import dataclass
from typing import TYPE_CHECKING, List, Optional, Set, Union from typing import TYPE_CHECKING, List, Optional, Set, Union
from urllib.parse import urldefrag, urljoin, urlparse from urllib.parse import urldefrag, urljoin, urlparse
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
from langchain_core.graph_vectorstores import Link from langchain_core.graph_vectorstores import Link
@ -61,6 +62,7 @@ class HtmlInput:
base_url: str base_url: str
@beta()
class HtmlLinkExtractor(LinkExtractor[HtmlInput]): class HtmlLinkExtractor(LinkExtractor[HtmlInput]):
def __init__(self, *, kind: str = "hyperlink", drop_fragments: bool = True): def __init__(self, *, kind: str = "hyperlink", drop_fragments: bool = True):
"""Extract hyperlinks from HTML content. """Extract hyperlinks from HTML content.

View File

@ -1,5 +1,6 @@
from typing import Any, Dict, Iterable, Optional, Set, Union from typing import Any, Dict, Iterable, Optional, Set, Union
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
from langchain_core.graph_vectorstores.links import Link from langchain_core.graph_vectorstores.links import Link
@ -10,6 +11,7 @@ from langchain_community.graph_vectorstores.extractors.link_extractor import (
KeybertInput = Union[str, Document] KeybertInput = Union[str, Document]
@beta()
class KeybertLinkExtractor(LinkExtractor[KeybertInput]): class KeybertLinkExtractor(LinkExtractor[KeybertInput]):
def __init__( def __init__(
self, self,

View File

@ -3,6 +3,7 @@ from __future__ import annotations
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Generic, Iterable, Set, TypeVar from typing import Generic, Iterable, Set, TypeVar
from langchain_core._api import beta
from langchain_core.graph_vectorstores import Link from langchain_core.graph_vectorstores import Link
InputT = TypeVar("InputT") InputT = TypeVar("InputT")
@ -10,6 +11,7 @@ InputT = TypeVar("InputT")
METADATA_LINKS_KEY = "links" METADATA_LINKS_KEY = "links"
@beta()
class LinkExtractor(ABC, Generic[InputT]): class LinkExtractor(ABC, Generic[InputT]):
"""Interface for extracting links (incoming, outgoing, bidirectional).""" """Interface for extracting links (incoming, outgoing, bidirectional)."""

View File

@ -1,5 +1,6 @@
from typing import Callable, Iterable, Set, TypeVar from typing import Callable, Iterable, Set, TypeVar
from langchain_core._api import beta
from langchain_core.graph_vectorstores import Link from langchain_core.graph_vectorstores import Link
from langchain_community.graph_vectorstores.extractors.link_extractor import ( from langchain_community.graph_vectorstores.extractors.link_extractor import (
@ -10,6 +11,7 @@ InputT = TypeVar("InputT")
UnderlyingInputT = TypeVar("UnderlyingInputT") UnderlyingInputT = TypeVar("UnderlyingInputT")
@beta()
class LinkExtractorAdapter(LinkExtractor[InputT]): class LinkExtractorAdapter(LinkExtractor[InputT]):
def __init__( def __init__(
self, self,

View File

@ -1,5 +1,6 @@
from typing import Any, Sequence from typing import Any, Sequence
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
from langchain_core.documents.transformers import BaseDocumentTransformer from langchain_core.documents.transformers import BaseDocumentTransformer
from langchain_core.graph_vectorstores.links import copy_with_links from langchain_core.graph_vectorstores.links import copy_with_links
@ -9,6 +10,7 @@ from langchain_community.graph_vectorstores.extractors.link_extractor import (
) )
@beta()
class LinkExtractorTransformer(BaseDocumentTransformer): class LinkExtractorTransformer(BaseDocumentTransformer):
"""DocumentTransformer for applying one or more LinkExtractors. """DocumentTransformer for applying one or more LinkExtractors.

View File

@ -32,6 +32,7 @@ def _has_next(iterator: Iterator) -> bool:
return next(iterator, sentinel) is not sentinel return next(iterator, sentinel) is not sentinel
@beta()
class Node(Serializable): class Node(Serializable):
"""Node in the GraphVectorStore. """Node in the GraphVectorStore.
@ -115,6 +116,7 @@ def _documents_to_nodes(documents: Iterable[Document]) -> Iterator[Node]:
) )
@beta()
def nodes_to_documents(nodes: Iterable[Node]) -> Iterator[Document]: def nodes_to_documents(nodes: Iterable[Node]) -> Iterator[Document]:
for node in nodes: for node in nodes:
metadata = node.metadata.copy() metadata = node.metadata.copy()

View File

@ -1,9 +1,11 @@
from dataclasses import dataclass from dataclasses import dataclass
from typing import Iterable, List, Literal, Union from typing import Iterable, List, Literal, Union
from langchain_core._api import beta
from langchain_core.documents import Document from langchain_core.documents import Document
@beta()
@dataclass(frozen=True) @dataclass(frozen=True)
class Link: class Link:
"""A link to/from a tag of a given tag. """A link to/from a tag of a given tag.
@ -38,6 +40,7 @@ class Link:
METADATA_LINKS_KEY = "links" METADATA_LINKS_KEY = "links"
@beta()
def get_links(doc: Document) -> List[Link]: def get_links(doc: Document) -> List[Link]:
"""Get the links from a document. """Get the links from a document.
Args: Args:
@ -54,6 +57,7 @@ def get_links(doc: Document) -> List[Link]:
return links return links
@beta()
def add_links(doc: Document, *links: Union[Link, Iterable[Link]]) -> None: def add_links(doc: Document, *links: Union[Link, Iterable[Link]]) -> None:
"""Add links to the given metadata. """Add links to the given metadata.
Args: Args:
@ -68,6 +72,7 @@ def add_links(doc: Document, *links: Union[Link, Iterable[Link]]) -> None:
links_in_metadata.append(link) links_in_metadata.append(link)
@beta()
def copy_with_links(doc: Document, *links: Union[Link, Iterable[Link]]) -> Document: def copy_with_links(doc: Document, *links: Union[Link, Iterable[Link]]) -> Document:
"""Return a document with the given links added. """Return a document with the given links added.