LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
LangChain
  • Browser
  • Universal
  • Hub
  • Node
  • Load
  • Serializable
  • Encoder Backed
  • File System
  • In Memory
  • Tools
LangChain Core
  • Agents
  • Caches
  • Base
  • Dispatch
  • Web
  • Manager
  • Promises
  • Chat History
  • Context
  • Base
  • Langsmith
  • Documents
  • Embeddings
  • Errors
  • Example Selectors
  • Indexing
  • Base
  • Chat Models
  • Compat
  • Event
  • Llms
  • Profile
  • Stream
  • Structured Output
  • Load
  • Serializable
  • Memory
  • Messages
  • Tool
  • Output Parsers
  • Openai Functions
  • Openai Tools
  • Outputs
  • Prompt Values
  • Prompts
  • Retrievers
  • Document Compressors
  • Runnables
  • Graph
  • Singletons
  • Stores
  • Structured Query
  • Testing
  • Tools
  • Base
  • Console
  • Log Stream
  • Run Collector
  • Tracer Langchain
  • Stream
  • Async Caller
  • Chunk Array
  • Context
  • Env
  • Event Source Parse
  • Format
  • Function Calling
  • Hash
  • Json Patch
  • Json Schema
  • Math
  • Ssrf
  • Standard Schema
  • Stream
  • Testing
  • Tiktoken
  • Types
  • Uuid
  • Vectorstores
Text Splitters
MCP Adapters
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

LangChain
BrowserUniversalHubNodeLoadSerializableEncoder BackedFile SystemIn MemoryTools
LangChain Core
AgentsCachesBaseDispatchWebManagerPromisesChat HistoryContextBaseLangsmithDocumentsEmbeddingsErrorsExample SelectorsIndexingBaseChat ModelsCompatEventLlmsProfileStreamStructured OutputLoadSerializableMemoryMessagesToolOutput ParsersOpenai FunctionsOpenai ToolsOutputsPrompt ValuesPromptsRetrieversDocument CompressorsRunnablesGraphSingletonsStoresStructured QueryTestingToolsBaseConsoleLog StreamRun CollectorTracer LangchainStreamAsync CallerChunk ArrayContextEnvEvent Source ParseFormatFunction CallingHashJson PatchJson SchemaMathSsrfStandard SchemaStreamTestingTiktokenTypesUuidVectorstores
Text Splitters
MCP Adapters
Language
Theme
JavaScript@langchain/corevectorstoresVectorStoreasRetriever
Methodā—Since v0.3

asRetriever

Copy
asRetriever(
  kOrFields: number | Partial<VectorStoreRetrieverInput<VectorStore>>,
  filter: string |
View source on GitHub
object
,
callbacks
:
Callbacks
,
tags
:
string
[
]
,
metadata
:
Record
<
string
,
unknown
>
,
verbose
:
boolean
)
:
VectorStoreRetriever
<
VectorStore
>

Parameters

NameTypeDescription
kOrFieldsnumber | Partial<VectorStoreRetrieverInput<VectorStore>>

If a number is provided, it sets the k parameter (number of items to retrieve).

  • If an object is provided, it should contain various configuration options.
filterstring | object

Optional filter criteria to limit the items retrieved based on the specified filter type.

callbacksCallbacks
tagsstring[]
metadataRecord<string, unknown>
verboseboolean

Example

Basic usage with a `k` value:

Copy
const retriever = myVectorStore.asRetriever(5);

Creates a VectorStoreRetriever instance with flexible configuration options.

Optional callbacks that may be triggered at specific stages of the retrieval process.

Tags to categorize or label the VectorStoreRetriever. Defaults to an empty array if not provided.

Additional metadata as key-value pairs to add contextual information for the retrieval process.

If true, enables detailed logging for the retrieval process. Defaults to false.