Skip to content

Commit

Permalink
feat: add frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
Rob Ellison committed Mar 18, 2024
1 parent 928479b commit 12bb658
Show file tree
Hide file tree
Showing 3 changed files with 171 additions and 54 deletions.
20 changes: 18 additions & 2 deletions app/api/chat/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,21 @@ import { RunnableBranch, RunnableSequence } from "@langchain/core/runnables";
import { PromptTemplate } from "@langchain/core/prompts";
import { StringOutputParser } from "@langchain/core/output_parsers";
import { formatDocumentsAsString } from "langchain/util/document";
import { RedisVectorStore } from "@langchain/community/vectorstores/redis";
import { RedisVectorStore } from "@langchain/redis";
import { createClient } from "redis";
import { ContextualCompressionRetriever } from "langchain/retrievers/contextual_compression";
import { EmbeddingsFilter } from "langchain/retrievers/document_compressors/embeddings_filter";
// import { Schema } from "@langchain/core";
import { RedisByteStore } from "@langchain/community/storage/ioredis";

const customSchema = {
id: "CustomSchema",
properties: {
title: { type: "string" },
url: { type: "string" },
file: { type: "string" },
},
};
// WARNING: PLEASE DO NOT USE Langsmith when using production data
// as this has not been checked and approved.
// Code for using Langsmith
Expand Down Expand Up @@ -60,13 +70,18 @@ export async function POST(req) {
url: process.env.REDIS_URL ?? `redis://${REDIS_HOST}:6379`,
});
await redisClient.connect();
console.log("Successfully connect to Redis");
console.log("Successfully connected to Redis");

const baseCompressor = new EmbeddingsFilter({
embeddings: new OpenAIEmbeddings(),
similarityThreshold: SIMILARITY_THRESHOLD,
});

const redisByteStore = new RedisByteStore({
client: redisClient,
schema: customSchema,
});

const vectorStore = new RedisVectorStore(new OpenAIEmbeddings(), {
redisClient: redisClient,
indexName: process.env.INDEX_NAME,
Expand Down Expand Up @@ -111,6 +126,7 @@ export async function POST(req) {
const extractDocSource = async (currentQuestion) => {
// code to extract sources from retrieverResult
relevantDocs = await retriever.getRelevantDocuments(currentQuestion);
console.log("Relevant Docs: ", relevantDocs);
return relevantDocs;
};

Expand Down
Loading

0 comments on commit 12bb658

Please sign in to comment.