Skip to content

Chatbot frontend for Anserini API #2695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/experiments-20newsgroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ total terms: 4219956

For reference, the number of docs indexed should be exactly as follows:

| | # of docs | pre-built index |
|---------------|----------:|-----------------|
| Train | 11,314 | [[download](https://www.dropbox.com/s/npg5eovr92h5k7w/lucene-index.20newsgroups.train.tar.gz)]
| Test | 7,532 | [[download](https://www.dropbox.com/s/aptj8hz9wti3qaf/lucene-index.20newsgroups.test.tar.gz)]
| Train + Test | 18,846 | [[download](https://www.dropbox.com/s/qo2wt6fzu01yt4c/lucene-index.20newsgroups.all.tar.gz)]
| | # of docs |
|---------------|-----------|
| Train | 11,314 |
| Test | 7,532 |
| Train + Test | 18,846 |

For convenience, we also provide pre-built indexes above.

Expand Down
92 changes: 46 additions & 46 deletions docs/experiments-cord19.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ For an easy way to get started, check out our (unfortunately, out of date) Colab

We provide instructions on how to build Lucene indexes for the collection using Anserini below, but if you don't want to bother building the indexes yourself, we have pre-built indexes that you can directly download:

| Version | Type | Size | Link | Checksum |
|:-----------|:----------|:------|:-----|:---------|
| 2020-07-16 | Abstract | 2.1G | [[Dropbox]](https://www.dropbox.com/s/9hfowxi7zenuaay/lucene-index-cord19-abstract-2020-07-16.tar.gz?dl=1) | `c883571ccc78b4c2ce05b41eb07f5405`
| 2020-07-16 | Full-Text | 4.1G | [[Dropbox]](https://www.dropbox.com/s/dyd9sggrqo44d0n/lucene-index-cord19-full-text-2020-07-16.tar.gz?dl=1) | `23cfad89b4c206d66125f5736f60248f`
| 2020-07-16 | Paragraph | 5.9G | [[Dropbox]](https://www.dropbox.com/s/jdfbrnohtkrvds5/lucene-index-cord19-paragraph-2020-07-16.tar.gz?dl=1) | `c2c6ac832f8a1fcb767d2356d2b1e1df`
| Version | Type | Size |
|:-----------|:----------|:------|
| 2020-07-16 | Abstract | 2.1G |
| 2020-07-16 | Full-Text | 4.1G |
| 2020-07-16 | Paragraph | 5.9G |

"Size" refers to the output of `ls -lh`, "Version" refers to the dataset release date from AI2.
For our answer to the question, "which one should I use?" see below.
Expand Down Expand Up @@ -185,47 +185,47 @@ The original raw JSON full text is stored in the `raw` field of `docid` (without

All versions of pre-built indexes:

| Version | Type | Size | Link | Checksum |
|:-----------|:----------|:------|:-----|:---------|
| 2020-07-16 | Abstract | 2.1G | [[Dropbox]](https://www.dropbox.com/s/9hfowxi7zenuaay/lucene-index-cord19-abstract-2020-07-16.tar.gz?dl=1) | `c883571ccc78b4c2ce05b41eb07f5405`
| 2020-07-16 | Full-Text | 4.1G | [[Dropbox]](https://www.dropbox.com/s/dyd9sggrqo44d0n/lucene-index-cord19-full-text-2020-07-16.tar.gz?dl=1) | `23cfad89b4c206d66125f5736f60248f`
| 2020-07-16 | Paragraph | 5.9G | [[Dropbox]](https://www.dropbox.com/s/jdfbrnohtkrvds5/lucene-index-cord19-paragraph-2020-07-16.tar.gz?dl=1) | `c2c6ac832f8a1fcb767d2356d2b1e1df`
| 2020-06-19 | Abstract | 2.0G | [[Dropbox]](https://www.dropbox.com/s/x8wbuy0atgnajfd/lucene-index-cord19-abstract-2020-06-19.tar.gz?dl=1) | `029bd55daba8800fbae2be9e5fcd7b33`
| 2020-06-19 | Full-Text | 3.8G | [[Dropbox]](https://www.dropbox.com/s/tf469r70r8aigu2/lucene-index-cord19-full-text-2020-06-19.tar.gz?dl=1) | `3d0eb12094a24cff9bcacd1f17c3ea1c`
| 2020-06-19 | Paragraph | 5.5G | [[Dropbox]](https://www.dropbox.com/s/fr3v69vhryevwp9/lucene-index-cord19-paragraph-2020-06-19.tar.gz?dl=1) | `5cd8cd6998177bed7a3e0057ef8b3595`
| 2020-06-12 | Abstract | 1.9G | [[Dropbox]](https://www.dropbox.com/s/bnc66r67r17cqg8/lucene-index-cord19-abstract-2020-06-12.tar.gz?dl=1) | `e0d9d312a83d67c21069717957a56f47`
| 2020-06-12 | Full-Text | 3.7G | [[Dropbox]](https://www.dropbox.com/s/z1cyolb7s606bvd/lucene-index-cord19-full-text-2020-06-12.tar.gz?dl=1) | `72018ee46556cc72d01885203ea386dc`
| 2020-06-12 | Paragraph | 5.3G | [[Dropbox]](https://www.dropbox.com/s/nvglwgcdcp8l20v/lucene-index-cord19-paragraph-2020-06-12.tar.gz?dl=1) | `72732d298885c2c317236af33b08197c`
| 2020-05-26 | Abstract | 1.7G | [[Dropbox]](https://www.dropbox.com/s/3vc4prdneqgfoe2/lucene-index-cord19-abstract-2020-05-26.tar.gz?dl=1) | `2dc054f4ca7db281e9f5e0d4836df14c`
| 2020-05-26 | Full-Text | 3.3G | [[Dropbox]](https://www.dropbox.com/s/frr1s8azvx8akbh/lucene-index-cord19-full-text-2020-05-26.tar.gz?dl=1) | `9b9fd4b97f75fa295e3345d0cf7914e3`
| 2020-05-26 | Paragraph | 4.7G | [[Dropbox]](https://www.dropbox.com/s/4mqzvkxymdou8vb/lucene-index-cord19-paragraph-2020-05-26.tar.gz?dl=1) | `72eb265c1c9983f02f1e79a2ba19befb`
| 2020-05-19 | Abstract | 1.7G | [[Dropbox]](https://www.dropbox.com/s/7bbz6pm4rduqvx3/lucene-index-cord19-abstract-2020-05-19.tar.gz?dl=1) | `37bb97d0c41d650ba8e135fd75ae8fd8`
| 2020-05-19 | Full-Text | 3.3G | [[Dropbox]](https://www.dropbox.com/s/bxhldgks1rxz4ly/lucene-index-cord19-full-text-2020-05-19.tar.gz?dl=1) | `f5711915a66cd2b511e0fb8d03e4c325`
| 2020-05-19 | Paragraph | 4.9G | [[Dropbox]](https://www.dropbox.com/s/2ewjchln0ihm6hh/lucene-index-cord19-paragraph-2020-05-19.tar.gz?dl=1) | `012ab1f804382b2275c433a74d7d31f2`
| 2020-05-12 | Abstract | 1.3G | [[Dropbox]](https://www.dropbox.com/s/8kdtjajvod8toe3/lucene-index-cord19-abstract-2020-05-12.tar.gz?dl=1) | `dfd09e70cd672bbe15a63437351e1f74`
| 2020-05-12 | Full-Text | 2.5G | [[Dropbox]](https://www.dropbox.com/s/pxyzdwk59tnv13k/lucene-index-cord19-full-text-2020-05-12.tar.gz?dl=1) | `5b914e8ae579195185cf28a60051236d`
| 2020-05-12 | Paragraph | 3.6G | [[Dropbox]](https://www.dropbox.com/s/z8s0urul6l4zig2/lucene-index-cord19-paragraph-2020-05-12.tar.gz?dl=1) | `a2cb36762078ef9373f0ddaf52618e7f`
| 2020-05-01 | Abstract | 1.2G | [[Dropbox]](https://www.dropbox.com/s/jdsc6wu0vbumpup/lucene-index-cord19-abstract-2020-05-01.tar.gz?dl=1) | `a06e71a98a68d31148cb0e97e70a2ee1`
| 2020-05-01 | Full-Text | 2.4G | [[Dropbox]](https://www.dropbox.com/s/ouvp7zyqsp9y9gh/lucene-index-cord19-full-text-2020-05-01.tar.gz?dl=1) | `e7eca1b976cdf2cd80e908c9ac2263cb`
| 2020-05-01 | Paragraph | 3.6G | [[Dropbox]](https://www.dropbox.com/s/e1118vjuf58ojt4/lucene-index-cord19-paragraph-2020-05-01.tar.gz?dl=1) | `8f9321757a03985ac1c1952b2fff2c7d`
| 2020-04-24 | Abstract | 1.3G | [[Dropbox]](https://www.dropbox.com/s/u7nmn3q8cn89jak/lucene-index-cord19-abstract-2020-04-24.tar.gz?dl=1) | `93540ae00e166ee433db7531e1bb51c8`
| 2020-04-24 | Full-Text | 2.4G | [[Dropbox]](https://www.dropbox.com/s/qk10yo8ijkhvw49/lucene-index-cord19-full-text-2020-04-24.tar.gz?dl=1) | `fa927b0fc9cf1cd382413039cdc7b736`
| 2020-04-24 | Paragraph | 5.0G | [[Dropbox]](https://www.dropbox.com/s/fcnkc85u4930ekl/lucene-index-cord19-paragraph-2020-04-24.tar.gz?dl=1) | `7c6de6298e0430b8adb3e03310db32d8`
| 2020-04-17 | Abstract | 1.2G | [[Dropbox]](https://www.dropbox.com/s/h5cwuf7mdwv9emn/lucene-index-covid-2020-04-17.tar.gz?dl=1) | `d57b17eadb1b44fc336b4121c139a598`
| 2020-04-17 | Full-Text | 2.2G | [[Dropbox]](https://www.dropbox.com/s/y6kkgms3igbd4li/lucene-index-covid-full-text-2020-04-17.tar.gz?dl=1) | `677546e0a1b7855a48eee8b6fbd7d7af`
| 2020-04-17 | Paragraph | 4.7G | [[Dropbox]](https://www.dropbox.com/s/f560j54eikvcym3/lucene-index-covid-paragraph-2020-04-17.tar.gz?dl=1) | `c11e46230b744a46747f84e49acc9c2b`
| 2020-04-10 | Abstract | 1.2G | [[Dropbox]](https://www.dropbox.com/s/iebape2yfgkzkt1/lucene-index-covid-2020-04-10.tar.gz?dl=1) | `ec239d56498c0e7b74e3b41e1ce5d42a`
| 2020-04-10 | Full-Text | 3.3G | [[Dropbox]](https://www.dropbox.com/s/pfouskfoxb471e6/lucene-index-covid-full-text-2020-04-10.tar.gz?dl=1) | `401a6f5583b0f05340c73fbbeb3279c8`
| 2020-04-10 | Paragraph | 3.4G | [[Dropbox]](https://www.dropbox.com/s/yr0bj5pxu2k89n0/lucene-index-covid-paragraph-2020-04-10.tar.gz?dl=1) | `8b87a2c55bc0a15b87f11e796860216a`
| 2020-04-03 | Abstract | 1.1G | [[Dropbox]](https://www.dropbox.com/s/at483ydl82lxp3m/lucene-index-covid-2020-04-03.tar.gz?dl=1) | `5d0d222e746d522a75f94240f5ab9f23`
| 2020-04-03 | Full-Text | 3.0G | [[Dropbox]](https://www.dropbox.com/s/1b0uc5bn8k6vjez/lucene-index-covid-full-text-2020-04-03.tar.gz?dl=1) | `9aafb86fec39e0882bd9ef0688d7a9cc`
| 2020-04-03 | Paragraph | 3.1G | [[Dropbox]](https://www.dropbox.com/s/cz43ffuq7lvpgc7/lucene-index-covid-paragraph-2020-04-03.tar.gz?dl=1) | `523894cfb52fc51c4202e76af79e1b10`
| 2020-03-27 | Abstract | 1.1G | [[Dropbox]](https://www.dropbox.com/s/uycipzfdy4liis4/lucene-index-covid-2020-03-27.tar.gz?dl=1) | `c5f7247e921c80f41ac6b54ff38eb229`
| 2020-03-27 | Full-Text | 2.9G | [[Dropbox]](https://www.dropbox.com/s/70644muwa5ir5ao/lucene-index-covid-full-text-2020-03-27.tar.gz?dl=1) | `3c126344f9711720e6cf627c9bc415eb`
| 2020-03-27 | Paragraph | 3.1G | [[Dropbox]](https://www.dropbox.com/s/g95935ndq6iu4d7/lucene-index-covid-paragraph-2020-03-27.tar.gz?dl=1) | `8e02de859317918af4829c6188a89086`
| 2020-03-20 | Abstract | 1.0G | [[Dropbox]](https://www.dropbox.com/s/vkdnuuf219b2fzf/lucene-index-covid-2020-03-20.tar.gz?dl=1) | `281c632034643665d52a544fed23807a`
| 2020-03-20 | Full-Text | 2.6G | [[Dropbox]](https://www.dropbox.com/s/6o4219f3968hzue/lucene-index-covid-full-text-2020-03-20.tar.gz?dl=1) | `30cae90b85fa8f1b53acaa62413756e3`
| 2020-03-20 | Paragraph | 2.9G | [[Dropbox]](https://www.dropbox.com/s/cssy06xpuh3mdqq/lucene-index-covid-paragraph-2020-03-20.tar.gz?dl=1) | `4c78e9ede690dbfac13e25e634c70ae4`
| Version | Type | Size |
|:-----------|:----------|:------|
| 2020-07-16 | Abstract | 2.1G |
| 2020-07-16 | Full-Text | 4.1G |
| 2020-07-16 | Paragraph | 5.9G |
| 2020-06-19 | Abstract | 2.0G |
| 2020-06-19 | Full-Text | 3.8G |
| 2020-06-19 | Paragraph | 5.5G |
| 2020-06-12 | Abstract | 1.9G |
| 2020-06-12 | Full-Text | 3.7G |
| 2020-06-12 | Paragraph | 5.3G |
| 2020-05-26 | Abstract | 1.7G |
| 2020-05-26 | Full-Text | 3.3G |
| 2020-05-26 | Paragraph | 4.7G |
| 2020-05-19 | Abstract | 1.7G |
| 2020-05-19 | Full-Text | 3.3G |
| 2020-05-19 | Paragraph | 4.9G |
| 2020-05-12 | Abstract | 1.3G |
| 2020-05-12 | Full-Text | 2.5G |
| 2020-05-12 | Paragraph | 3.6G |
| 2020-05-01 | Abstract | 1.2G |
| 2020-05-01 | Full-Text | 2.4G |
| 2020-05-01 | Paragraph | 3.6G |
| 2020-04-24 | Abstract | 1.3G |
| 2020-04-24 | Full-Text | 2.4G |
| 2020-04-24 | Paragraph | 5.0G |
| 2020-04-17 | Abstract | 1.2G |
| 2020-04-17 | Full-Text | 2.2G |
| 2020-04-17 | Paragraph | 4.7G |
| 2020-04-10 | Abstract | 1.2G |
| 2020-04-10 | Full-Text | 3.3G |
| 2020-04-10 | Paragraph | 3.4G |
| 2020-04-03 | Abstract | 1.1G |
| 2020-04-03 | Full-Text | 3.0G |
| 2020-04-03 | Paragraph | 3.1G |
| 2020-03-27 | Abstract | 1.1G |
| 2020-03-27 | Full-Text | 2.9G |
| 2020-03-27 | Paragraph | 3.1G |
| 2020-03-20 | Abstract | 1.0G |
| 2020-03-20 | Full-Text | 2.6G |
| 2020-03-20 | Paragraph | 2.9G |

These indexes are also mirrored [here](https://git.uwaterloo.ca/jimmylin/cord19-indexes/).

Expand Down
22 changes: 22 additions & 0 deletions src/main/anserini-chatbot/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": [
"next/core-web-vitals",
"plugin:import/recommended",
"plugin:import/typescript",
"prettier",
"plugin:tailwindcss/recommended"
],
"plugins": ["tailwindcss"],
"rules": {
"tailwindcss/no-custom-classname": "off",
"tailwindcss/classnames-order": "off"
},
"settings": {
"import/resolver": {
"typescript": {
"alwaysTryTypes": true
}
}
},
"ignorePatterns": ["**/components/ui/**"]
}
25 changes: 25 additions & 0 deletions src/main/anserini-chatbot/.github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Lint
on:
push:

jobs:
build:
runs-on: ubuntu-22.04
strategy:
matrix:
node-version: [20]
steps:
- uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- name: Install dependencies
run: pnpm install
- name: Run lint
run: pnpm lint
38 changes: 38 additions & 0 deletions src/main/anserini-chatbot/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
node_modules
.pnp
.pnp.js

# testing
coverage

# next.js
.next/
out/
build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*
.pnpm-debug.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# turbo
.turbo

.env
.vercel
.vscode
.env*.local
13 changes: 13 additions & 0 deletions src/main/anserini-chatbot/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Copyright 2024 Vercel, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
109 changes: 109 additions & 0 deletions src/main/anserini-chatbot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# AI-Powered Search Interface

A modern web application that provides a chat-like interface for interacting with various search indexes through Anserini's search API, built on top of Vercel's ([AI Chatbot Template](https://github.com/vercel/ai-chatbot)).

## Features

### Search Models
- **MS MARCO Collection**
- Base Indexes (V1/V2)
- Neural Encodings:
- SPLADE++ CoCondenser-EnsembleDistil
- cos-DPR Distil (HNSW & quantized INT8)
- BGE-base-en-v1.5 (HNSW & quantized INT8)
- Cohere embed-english-v3.0 (HNSW & quantized INT8)
- **BEIR Collections**
- Multiple collections (TREC-COVID, BioASQ, etc.)
- Index types: Flat, Multifield, SPLADE++, BGE
- **CACM Collection**
- Classic IR test collection

### Chat Interface
- Conversational interaction with search results
- Real-time streaming responses
- Support for both search and chat models
- Message history and chat persistence

## Architecture

### Core Components
- Next.js 13+ with App Router
- TypeScript for type safety
- Vercel AI SDK for streaming
- Server-side API routes for search functionality

### Search Integration
- Direct integration with Anserini's Java backend APIs
- Support for multiple index types:
- Traditional Lucene indexes
- Neural HNSW indexes
- Quantized (INT8) indexes
- Impact indexes (SPLADE++)

### Data Flow
1. User sends query through chat interface
2. Query is processed by appropriate model
3. For search models:
- Query is sent to Anserini backend
- Results are formatted and streamed back
4. For chat models:
- Interaction is handled by chat API
- Responses are streamed in real-time

## Running locally

You will need to use the environment variables [defined in `.env.example`](.env.example) to run the application. It's recommended you use [Vercel Environment Variables](https://vercel.com/docs/projects/environment-variables) for this, but a `.env` file is all that is necessary.

> Note: You should not commit your `.env` file or it will expose secrets that will allow others to control access to your various OpenAI and authentication provider accounts.

1. Install Vercel CLI: `npm i -g vercel`
2. Link local instance with Vercel and GitHub accounts (creates `.vercel` directory): `vercel link`
3. Download your environment variables: `vercel env pull`

Then install dependencies and start the development server:

```bash
pnpm install
pnpm tsx lib/db/migrate.ts && pnpm run build
pnpm dev
```

Your app should now be running on [localhost:3000](http://localhost:3000/).

## Configuration

### Anserini Server
The application expects an Anserini server running at the configured host/port with the following settings:
```json
{
"host": "localhost",
"port": 8081,
"apiVersion": "v1.0"
}
```

### Available Models
Models are configured in `lib/ai/models.ts` and include:
- Chat models for query assistance
- Search models for different collections and encodings

## Deploy Your Own

You can deploy your own version of the application to Vercel with one click:

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fvercel%2Fai-chatbot&env=AUTH_SECRET,OPENAI_API_KEY&envDescription=Learn%20more%20about%20how%20to%20get%20the%20API%20Keys%20for%20the%20application&envLink=https%3A%2F%2Fgithub.com%2Fvercel%2Fai-chatbot%2Fblob%2Fmain%2F.env.example&demo-title=AI%20Chatbot&demo-description=An%20Open-Source%20AI%20Chatbot%20Template%20Built%20With%20Next.js%20and%20the%20AI%20SDK%20by%20Vercel.&demo-url=https%3A%2F%2Fchat.vercel.ai&stores=[{%22type%22:%22postgres%22},{%22type%22:%22blob%22}])

## API Integration

See `API_INTEGRATION.md` for detailed information about integrating with the Anserini backend and available endpoints.

## Development

The application uses a modern React stack with:
- Next.js App Router for routing
- Server Components for improved performance
- Streaming for real-time updates
- TypeScript for type safety
- [shadcn/ui](https://ui.shadcn.com) with Tailwind CSS
- [Vercel Postgres](https://vercel.com/storage/postgres) for data persistence
- [NextAuth.js](https://github.com/nextauthjs/next-auth) for authentication
Loading