Home / File/ in_memory.py — langchain Source File

in_memory.py — langchain Source File

Architecture documentation for in_memory.py, a python file in the langchain codebase. 12 imports, 0 dependents.

File python CoreAbstractions RunnableInterface 12 imports 3 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  eb1e92dc_3a47_90f7_13c1_755c92499dc6["in_memory.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  8dfa0cac_d802_3ccd_f710_43a5e70da3a5["uuid"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> 8dfa0cac_d802_3ccd_f710_43a5e70da3a5
  b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8["pathlib"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> b6ee5de5_719a_eeb5_1e11_e9c63bc22ef8
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> 91721f45_4909_e489_8c1f_084f8bd87145
  c554676d_b731_47b2_a98f_c1c2d537c0aa["langchain_core.documents"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> c554676d_b731_47b2_a98f_c1c2d537c0aa
  36cce5da_d805_04c3_7e86_e1b4dd49b497["langchain_core.load"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> 36cce5da_d805_04c3_7e86_e1b4dd49b497
  d55af636_303c_0eb6_faee_20d89bd952d5["langchain_core.vectorstores"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> d55af636_303c_0eb6_faee_20d89bd952d5
  a695ba33_7a5e_b01f_4714_d4ad0100a6dc["langchain_core.vectorstores.utils"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> a695ba33_7a5e_b01f_4714_d4ad0100a6dc
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3["langchain_core.embeddings"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> bc46b61d_cfdf_3f6b_a9dd_ac2a328d84b3
  cd17727f_b882_7f06_aadc_71fbf75bebb0["numpy"]
  eb1e92dc_3a47_90f7_13c1_755c92499dc6 --> cd17727f_b882_7f06_aadc_71fbf75bebb0
  style eb1e92dc_3a47_90f7_13c1_755c92499dc6 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""In-memory vector store."""

from __future__ import annotations

import json
import uuid
from pathlib import Path
from typing import (
    TYPE_CHECKING,
    Any,
)

from typing_extensions import override

from langchain_core.documents import Document
from langchain_core.load import dumpd, load
from langchain_core.vectorstores import VectorStore
from langchain_core.vectorstores.utils import _cosine_similarity as cosine_similarity
from langchain_core.vectorstores.utils import maximal_marginal_relevance

if TYPE_CHECKING:
    from collections.abc import Callable, Iterator, Sequence

    from langchain_core.embeddings import Embeddings

try:
    import numpy as np

    _HAS_NUMPY = True
except ImportError:
    _HAS_NUMPY = False


class InMemoryVectorStore(VectorStore):
    """In-memory vector store implementation.

    Uses a dictionary, and computes cosine similarity for search using numpy.

    Setup:
        Install `langchain-core`.

        ```bash
        pip install -U langchain-core
        ```

    Key init args — indexing params:

        * embedding_function: Embeddings
            Embedding function to use.

    Instantiate:
        ```python
        from langchain_core.vectorstores import InMemoryVectorStore
        from langchain_openai import OpenAIEmbeddings

        vector_store = InMemoryVectorStore(OpenAIEmbeddings())
        ```

    Add Documents:
        ```python
// ... (487 more lines)

Subdomains

Dependencies

  • collections.abc
  • json
  • langchain_core.documents
  • langchain_core.embeddings
  • langchain_core.load
  • langchain_core.vectorstores
  • langchain_core.vectorstores.utils
  • numpy
  • pathlib
  • typing
  • typing_extensions
  • uuid

Frequently Asked Questions

What does in_memory.py do?
in_memory.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in in_memory.py?
in_memory.py defines 3 function(s): _HAS_NUMPY, collections, numpy.
What does in_memory.py depend on?
in_memory.py imports 12 module(s): collections.abc, json, langchain_core.documents, langchain_core.embeddings, langchain_core.load, langchain_core.vectorstores, langchain_core.vectorstores.utils, numpy, and 4 more.
Where is in_memory.py in the architecture?
in_memory.py is located at libs/core/langchain_core/vectorstores/in_memory.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/langchain_core/vectorstores).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free