Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
PORT=3000
TAVILY_API_KEY=tvly-......
GOOGLE_AI_API_KEY=AI........
GOOGLE_AI_API_KEY=AI........
MONGODB_URI=
3 changes: 3 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
"dependencies": {
"@tavily/core": "^0.0.2",
"@types/cors": "^2.8.17",
"@types/mongoose": "^5.11.96",
"cors": "^2.8.5",
"dotenv": "^16.4.1",
"express": "^4.18.2",
"mongodb": "^6.13.0",
"mongoose": "^8.10.1",
"openai": "^4.26.0"
},
"devDependencies": {
Expand Down
12 changes: 12 additions & 0 deletions backend/src/config/database.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mongo from 'mongoose';

export const connectDatabase = async () => {
try {
const connection = await mongo.connect(process.env.MONGODB_URI!);
console.log('MongoDB connected:', connection.connection.host);
return connection;
} catch (e) {
console.error('MongoDB connection error:', e);
throw e;
}
};
124 changes: 124 additions & 0 deletions backend/src/models/SearchQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import mongoose from 'mongoose';

const searchQuerySchema = new mongoose.Schema(
{
query: {
type: String,
required: true,
},
timestamp: {
type: Date,
default: Date.now,
},
status: {
type: String,
enum: ['success', 'error'],
default: 'success',
},
ipHash: {
type: String,
},
userAgent: {
type: String,
},
sessionId: {
type: String,
},
followUpMode: {
type: String,
enum: ['expansive', 'focused'],
},
concept: String,
parentSearchId: {
type: mongoose.Schema.Types.ObjectId,
ref: 'SearchQuery',
},
conversationHistory: [
{
query: String,
nodeId: String,
response: {
response: String,
followUpQuestions: [String],
contextualQuery: String,
sources: [
{
title: String,
url: String,
uri: String,
author: String,
image: String,
},
],
images: [
{
url: String,
thumbnail: String,
description: String,
},
],
},
timestamp: {
type: Date,
default: Date.now,
},
},
],
currentNodes: [
{
id: String,
type: String,
data: mongoose.Schema.Types.Mixed,
position: {
x: Number,
y: Number,
},
style: mongoose.Schema.Types.Mixed,
},
],
currentEdges: [
{
id: String,
source: String,
target: String,
type: String,
style: mongoose.Schema.Types.Mixed,
},
],
searchResults: {
response: String,
followUpQuestions: [String],
contextualQuery: String,
sources: [
{
title: String,
url: String,
uri: String,
author: String,
image: String,
},
],
images: [
{
url: String,
thumbnail: String,
description: String,
},
],
},
error: {
type: String,
},
},
{
timestamps: true,
}
);

searchQuerySchema.index({ timestamp: -1 });
searchQuerySchema.index({ status: 1 });
searchQuerySchema.index({ ipHash: 1 });

export const SearchQuery =
mongoose.models.SearchQuery ||
mongoose.model('SearchQuery', searchQuerySchema);
Loading