Skip to content

LLM to search through large story database

Hi,

let me outline my situation. I have a database of thousands of short stories (roughly 1.5gb in size of pure raw text), which I want to efficiently search through. By searching, I mean 'finding stories with X theme' (e.g. horror story with fear of the unknown), or 'finding stories with X plotpoint' and so on.

I do not wish to filter through the stories manually and as to my limited knowledge, AI (or LLMs) seems like a perfect tool for the job of searching through the database while being aware of the context of the stories, compared to simple keyword search.

What would nowdays be the optimal solution for the job? I've looked up the concept of RAG, which *seems* to me, like it could fit the bill. There are solutions like AnythingLLM, where this could be apparently set-up, with using a model like ollama (or better - Please do recommend the best ones for this job) to handle the summarisation/search.

Now I am not a tech-illiterate, but apart from running ComfyUI and some other tools, I have practically zero experience with using LLMs locally, and especially using them for this purpose.

Could you suggest to me some tools (ideally local), which would be fitting in this situation - contextually searching through a database of raw text stories?

I'd greatly appreaciate your knowledge, thank you!

Just to note, I have 1080 GPU with 16GB of RAM, if that is enough.

7 points12 comments
Open on Reddit
About this post
Posted
Archived
Score
7 · 100% up
Kind
Text
ID
1pkcbui

Author

31
posts
9
comments
1
media
View profile

13 comments

Loook into cosine similarity and vector database. You can embed a short description and keywords separately and to a cosine search to find similarities.  This is usually paired with a regular semantic keyword search. 

3 points

1.5GB of stories raw text is just awesome, that's a cool project ! You're definitely thinking right about RAG for themes and context – a simple keyword search just doesn't cut it for that.

With a GTX 1080 and 16GB RAM, you're in a common spot. If you want to go 100% local for everything, you absolutely can! You'd be looking at Ollama for the LLM (running a quantized 7B or 8B model) paired with a local vector DB, and a frontend like Open WebUI or even AnythingLLM (which you mentioned) for the interface. But honestly, embedding and indexing all 1.5GB of that text is going to be your biggest hurdle on a 1080. It'll take ages, and you'd have to pick some really tiny embedding models to keep it snappy.

This is actually a sweet spot for a hybrid approach, which is what I've been focused on. Full disclosure: I'm a dev on Tensor Pilot, and that's exactly what it's built for. It lives on your desktop, handles all the local database management, but then uses your own Enterprise API keys (like from OpenAI or Gemini) for the heavy lifting, the embeddings, File Search and Model selections. You can create your own Knowledge Base with Gemini and OpenAI file search as well from desktop app. TP supports I/O for image, video, text and audio.

The big win there? Your 1080 doesn't get completely swamped crunching all that data, and because you're using your own API keys, your data falls under enterprise agreements, so they typically won't train on it. It gives you that privacy 'cookie' without needing a monster rig for the initial setup. Just to be clear, it's not air-gapped as Ollama, but it handles that compute-heavy part smart for your setup.

Hope it helps !! : )

https://preview.redd.it/q9m3khodou6g1.png?width=2930&format=png&auto=webp&s=08289c0befcae107450ab54bb64cdd8b1c197c03

2 points

It depends on exactly how you want to search. But I would actually probably advise the PGSQL fulltext module or Elasticsearch first and only switch away from those if there's a specific semantic processing feature that mandates using a RAG engine. Another thing that could be wise is a hybrid strategy of full text storage and indexing first then feed each to a LLM with instructions to produce a summary. Provided they are not so huge they overwhelm the context buffer and scramble the LLM's memory. 

1 points
CreaturesDigitalRemoved · saved before deletion

Yes rag makes sense but it's not as straightforward to dump it in a rag and your LLM will do what you are expecting. Rag traditionally use embeddings (chunking, optional compressing and storing in a vector database) semantic search is useful but it is slow so you need an indexer or classifications of your data, so when searching it maps looks at higher level of classifications first to granular retrieve the data. Memory retrieval and orchestration require several levels while balancing results with performance. All doable there a ready to download rag stacks, if you only deal with text your fine with embedding if dealing with images or PDFs it gets computational heavy (ocr and vlm). Your welcome to try it out on our platform where we take care of the orchestration and infrastructure layers, it's possible to use your self hosted ollama model to drive the agent. We just soft launched and have currently no documentation but if you like to try it out we have a free sign up with enough credits to test without commitment. Https://zaun.creatures.digital

1 points

You don't need AI to search and categorize content but AI can absolutely create a search tool for you to search your own content really easily. Or just learn how to use ripgrep.

1 points

"Optimal" means a lot of things.

In terms of speed of setting up some solution, AnythingLLM and RAG is probably the most straightforward. If you've never touched LLMs in your life, then you should be able to learn it in a week of spare time.

In terms of "highest performance" solutions, you can use any LLM chat out there to create an index card for each story, following a structure like:

title:
themes:
tropes:
genres:
subgenres:

etc., and the LLM fills it in for you. Customize to your needs.

If you do this manually for 1000 stories, it will take you around 16 hours to go through the whole batch, assuming 1 minute processing per story.

With the resulting index, you can search keywords with virtually any program out there that has a search function, and you also don't need more expertise than a "copy paste" workflow.

That said, if you suddenly change the index card template, you'll have to start all over again, so I recommend workshopping the template and make it as comprehensive as possible before moving ahead with two weeks of clerical work.

Of course, an automated solution is ideal, but I haven't encountered one. In any case, this is the general style of solution you'll want if you value retrieval speed and app-agnostic search above all else.

1 points

Docfetcher. Index all text. Type some keywords and it will give you percentage the document U r likely to be used. And there's a free version

1 points

Honestly I think a traditional document search will work better and faster than an LLM solution.

If needed, you could have an LLM do a single pass over the stories to generate tags and identify themes and then search that.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.