-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into adopt-secret-amazon_chat
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from haystack import Document, Pipeline | ||
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever | ||
from haystack.document_stores.in_memory import InMemoryDocumentStore | ||
from haystack_integrations.components.embedders.fastembed import FastembedDocumentEmbedder, FastembedTextEmbedder | ||
|
||
document_store = InMemoryDocumentStore(embedding_similarity_function="cosine") | ||
|
||
documents = [ | ||
Document(content="My name is Wolfgang and I live in Berlin"), | ||
Document(content="I saw a black horse running"), | ||
Document(content="Germany has many big cities"), | ||
Document(content="fastembed is supported by and maintained by Qdrant."), | ||
] | ||
|
||
document_embedder = FastembedDocumentEmbedder() | ||
document_embedder.warm_up() | ||
documents_with_embeddings = document_embedder.run(documents)["documents"] | ||
document_store.write_documents(documents_with_embeddings) | ||
|
||
query_pipeline = Pipeline() | ||
query_pipeline.add_component("text_embedder", FastembedTextEmbedder()) | ||
query_pipeline.add_component("retriever", InMemoryEmbeddingRetriever(document_store=document_store)) | ||
query_pipeline.connect("text_embedder.embedding", "retriever.query_embedding") | ||
|
||
query = "Who supports fastembed?" | ||
|
||
result = query_pipeline.run({"text_embedder": {"text": query}}) | ||
|
||
print(result["retriever"]["documents"][0]) # noqa: T201 | ||
|
||
# Document(id=..., | ||
# content: 'fastembed is supported by and maintained by Qdrant.', | ||
# score: 0.758..) |