Skip to main content
The NebiusRetriever enables efficient similarity search using embeddings from Nebius Token Factory. It leverages high-quality embedding models to enable semantic search over documents. This retriever is optimized for scenarios where you need to perform similarity search over a collection of documents, but don’t need to persist the vectors to a vector database. It performs vector similarity search in-memory using matrix operations, making it efficient for medium-sized document collections.

Setup

Installation

The Nebius integration can be installed via pip:

Credentials

Nebius requires an API key that can be passed as an initialization parameter api_key or set as the environment variable NEBIUS_API_KEY. You can obtain an API key by creating an account on Nebius Token Factory.

Instantiation

The NebiusRetriever requires a NebiusEmbeddings instance and a list of documents. Here’s how to initialize it:

Usage

Retrieve relevant documents

You can use the retriever to find documents related to a query:

Using get_relevant_documents

You can also use the get_relevant_documents method directly (though invoke is the preferred interface):

Customizing number of results

You can adjust the number of results at query time by passing k as a parameter:

Async support

NebiusRetriever supports async operations:

Handling empty documents

Use within a chain

NebiusRetriever works seamlessly in LangChain RAG pipelines. Here’s an example of creating a simple RAG chain with the NebiusRetriever:

Creating a search tool

You can use the NebiusRetrievalTool to create a tool for agents:

How it works

The NebiusRetriever works by:
  1. During initialization:
    • It stores the provided documents
    • It uses the provided NebiusEmbeddings to compute embeddings for all documents
    • These embeddings are stored in memory for quick retrieval
  2. During retrieval (invoke or get_relevant_documents):
    • It embeds the query using the same embedding model
    • It computes similarity scores between the query embedding and all document embeddings
    • It returns the top-k documents sorted by similarity
This approach is efficient for medium-sized document collections, as it avoids the need for a separate vector database while still providing high-quality semantic search.

API reference

For more details about the Nebius Token Factory API, visit the Nebius Token Factory Documentation.