open-index/open-npm huggingface dataset:
npm package: @objective-inc/langchain-retriever
Description: A lightweight wrapper around LangChain's retrieval functionality, designed to work seamlessly with Objective's search API.
Latest version: 1.0.7

# @objective-inc/langchain-retriever

A lightweight wrapper around LangChain's retrieval functionality, designed to work seamlessly with Objective's search API.

## Features

- Seamless integration with Objective's search API
- Configurable search parameters
- Compatible with LangChain's retrieval interfaces
- Type-safe implementation in TypeScript

## Installation

```bash
# npm
npm install @objective-inc/langchain-retriever

# yarn
yarn add @objective-inc/langchain-retriever

# pnpm
pnpm add @objective-inc/langchain-retriever
```

## Configuration Options

The `ObjectiveRetriever` accepts the following configuration options:

```typescript
interface ObjectiveRetrieverInput {
  indexId: string; // Required: The ID of your Objective search index
  apiKey: string; // Required: Your Objective API key
  limit?: number; // Optional: Maximum number of results (default: 1)
  objectFields?: string; // Optional: Fields to return in results (default: "")
  rankingExpr?: string; // Optional: Custom ranking expression
}
```

## Usage

```typescript
import { MultiQueryRetriever } from "langchain/retrievers/multi_query"
import { ChatOpenAI } from "@langchain/openai"
import { ObjectiveRetriever } from "@objective-inc/langchain-retriever";

// Initialize the retriever
const retriever = new ObjectiveRetriever({
  indexId,
  apiKey,
});

// Retrieve relevant documents
const documents = await retriever.getRelevantDocuments("your query here");
```

## Advanced Usage

```typescript
const retriever = new ObjectiveRetriever({
  indexId,
  apiKey,
  objectFields: "title,content,metadata", // Specify fields to return
  limit: 5 // Return up to 5 results
});
```

### Integration with LangChain

The retriever can be used with other LangChain components:

```typescript
import { MultiQueryRetriever } from "langchain/retrievers/multi_query";
import { ChatOpenAI } from "@langchain/openai";

// Create a base retriever
const baseRetriever = new ObjectiveRetriever({
  indexId,
  apiKey,
});

// Use with MultiQueryRetriever for enhanced retrieval
const model = new ChatOpenAI({
  modelName: "gpt-4o",
  temperature: 0,
  openAIApiKey,
  streaming: true,
})

const multiQueryRetriever = MultiQueryRetriever.fromLLM({
  llm: model,
  retriever: objectiveRetriever,
  verbose: false,
})

const documents = await multiQueryRetriever.getRelevantDocuments("your query");
```

## Error Handling

The retriever includes built-in error handling for:
- Invalid queries
- API connection issues
- Authentication errors

## TypeScript Support

This package is written in TypeScript and includes full type definitions for all features.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.