1.0.7 • Published 10 months ago

@objective-inc/langchain-retriever v1.0.7

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

@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

# 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:

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

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

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:

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.

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago