NeuralDB is a CPU-friendly and fine-tunable retrieval engine developed by ThirdAI.
InitializationThere are two initialization methods:
For all of the following initialization methods, the thirdai_key
parameter can be ommitted if the THIRDAI_KEY
environment variable is set.
ThirdAI API keys can be obtained at https://www.thirdai.com/try-bolt/
from langchain_community.retrievers import NeuralDBRetriever
retriever = NeuralDBRetriever.from_scratch(thirdai_key="your-thirdai-key")
retriever = NeuralDBRetriever.from_checkpoint(
checkpoint="/path/to/checkpoint.ndb",
thirdai_key="your-thirdai-key",
)
Inserting document sources
retriever.insert(
sources=["/path/to/doc.pdf", "/path/to/doc.docx", "/path/to/doc.csv"],
train=True,
fast_mode=True,
)
from thirdai import neural_db as ndb
retriever.insert(
sources=[
ndb.PDF(
"/path/to/doc.pdf",
version="v2",
chunk_size=100,
metadata={"published": 2022},
),
ndb.Unstructured("/path/to/deck.pptx"),
]
)
Retrieving documents
To query the retriever, you can use the standard LangChain retriever method get_relevant_documents
, which returns a list of LangChain Document objects. Each document object represents a chunk of text from the indexed files. For example, it may contain a paragraph from one of the indexed PDF files. In addition to the text, the document's metadata field contains information such as the document's ID, the source of this document (which file it came from), and the score of the document.
documents = retriever.invoke("query", top_k=10)
Fine tuning
NeuralDBRetriever can be fine-tuned to user behavior and domain-specific knowledge. It can be fine-tuned in two ways:
retriever.associate(source="source phrase", target="target phrase")
retriever.associate_batch(
[
("source phrase 1", "target phrase 1"),
("source phrase 2", "target phrase 2"),
]
)
retriever.upvote(query="how is a car manufactured", document_id=52)
retriever.upvote_batch(
[
("query 1", 52),
("query 2", 20),
]
)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4